package com.jsh.erp.service.systemConfig;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.google.common.collect.Sets;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.*;
import com.jsh.erp.datasource.mappers.*;
import com.jsh.erp.datasource.vo.DepotItemVo4Stock;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.exception.JshException;
import com.jsh.erp.service.WorkflowConfigProcess.WorkflowConfigProcessService;
import com.jsh.erp.service.accountHead.AccountHeadService;
import com.jsh.erp.service.depot.DepotService;
import com.jsh.erp.service.depotHead.DepotHeadService;
import com.jsh.erp.service.depotItem.DepotItemService;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.promotionHead.PromotionHeadService;
import com.jsh.erp.service.redis.RedisService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.IdUtils;
import com.jsh.erp.utils.NoticeUtil;
import com.jsh.erp.utils.ResourcesUtil;
import com.jsh.erp.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class SystemConfigService {
    private Logger logger = LoggerFactory.getLogger(SystemConfigService.class);

    @Resource
    private SystemConfigMapper systemConfigMapper;

    @Resource
    private SystemConfigMapperEx systemConfigMapperEx;
    @Resource
    private UserService userService;
    @Resource
    private LogService logService;
    @Resource
    private AccountHeadMapper accountHeadMapper;
    @Resource
    private AccountItemMapper accountItemMapper;
    @Resource
    private AccountMapper accountMapper;
    @Resource
    private AttachmentMapper attachmentMapper;
    @Resource
    private AttachmentMapperEx attachmentMapperEx;
    @Resource
    private DepotHeadMapper depotHeadMapper;
    @Resource
    private DepotHeadMapperEx depotHeadMapperEx;
    @Resource
    private DepotItemMapper depotItemMapper;
    @Resource
    private DepotItemMapperEx depotItemMapperEx;
    @Resource
    private DepotMapper depotMapper;
    @Resource
    private DepotMapperEx depotMapperEx;
    //    @Resource
//    private FunctionMapper functionMapper;
    @Resource
    private InOutItemMapper inOutItemMapper;
    @Resource
    private MaterialAttributeMapper materialAttributeMapper;
    @Resource
    private MaterialCategoryMapper materialCategoryMapper;
    @Resource
    private MaterialCurrentStockMapper materialCurrentStockMapper;
    @Resource
    private MaterialExtendMapper materialExtendMapper;
    @Resource
    private MaterialExtendMapperEx materialExtendMapperEx;
    @Resource
    private MaterialInitialStockMapper materialInitialStockMapper;
    @Resource
    private MaterialMapper materialMapper;
    @Resource
    private MaterialMapperEx materialMapperEx;
    @Resource
    private MaterialPropertyMapper materialPropertyMapper;
    @Resource
    private MsgMapper msgMapper;
    @Resource
    private OrganizationMapper organizationMapper;
    @Resource
    private OrgaUserRelMapper orgaUserRelMapper;
    @Resource
    private PersonMapper personMapper;
    //    @Resource
//    private PlatformConfigMapper platformConfigMapper;
    @Resource
    private PromotionDepotMapper promotionDepotMapper;
    @Resource
    private PromotionGiftMapper promotionGiftMapper;
    @Resource
    private PromotionHeadMapper promotionHeadMapper;
    @Resource
    private PromotionItemMapper promotionItemMapper;
    @Resource
    private PromotionSupplierMapper promotionSupplierMapper;
    @Resource
    private PromotionHeadMapperEx promotionHeadMapperEx;
    @Resource
    private PromotionHeadService promotionHeadService;
    @Resource
    private RebateItemMapper rebateItemMapper;
    @Resource
    private RebateMapper rebateMapper;
    @Resource
    private RebateMaterialMapper rebateMaterialMapper;
    @Resource
    private RebateRuleMapper rebateRuleMapper;
    @Resource
    private RoleMapper roleMapper;
    @Resource
    private SerialNumberMapper serialNumberMapper;
    @Resource
    private SupplierMapper supplierMapper;
    //    @Resource
//    private SystemConfigMapper systemConfigMapper;
    @Resource
    private TenantMapper tenantMapper;
    @Resource
    private UnitMapper unitMapper;
    @Resource
    private UnitMapperEx unitMapperEx;
    @Resource
    private UserBusinessMapper userBusinessMapper;
    @Resource
    private UserCategoryMapper userCategoryMapper;
    @Resource
    private UserMapper userMapper;
    @Resource
    private WorkflowApproveDetailMapper workflowApproveDetailMapper;
    @Resource
    private WorkflowConfigDetailMapper workflowConfigDetailMapper;
    @Resource
    private WorkflowConfigMainMapper workflowConfigMainMapper;
    @Resource
    private WorkflowProcessDetailHisMapper workflowProcessDetailHisMapper;
    @Resource
    private WorkflowProcessDetailMapper workflowProcessDetailMapper;
    @Resource
    private CashBoxRecordMapper cashBoxRecordMapper;
    @Resource
    private RetailRecordMapper retailRecordMapper;
    @Resource
    private RedisService redisService;
    private static final String TEST_USER = "jsh";
//    @Value(value = "${user.tenant.id}")
//    private String tenantId;
    @Resource
    private SynchronizationTaskMapperEx synchronizationTaskMapperEx;
    @Resource
    private AddressMapper addressMapper;
    @Resource
    private TransportMapper transportMapper;
    @Resource
    private DepotHeadService depotHeadService;
    @Resource
    private DepotItemService depotItemService;
    @Resource
    private WorkflowConfigProcessService workflowConfigProcessService;
    @Value(value = "${update.audit.url}")
    private String auditUrl;
    @Resource
    private AccountHeadService accountHeadService;
    @Resource
    private DepotService depotService;

    private static final String tenantId = ResourcesUtil.getValue("TenantId", "user.tenant.id");
    /**
     * @Author: wy
     * @Description: 查询分店数据
     * @DateTime: 2022-08-23 17:26
     * @Params:
     * @Return
     */
    public JSONObject getNewJsonObject() {
        JSONObject oldJsonObject = new JSONObject();
        //财务单据表头
        AccountHeadExample accountHeadExample = new AccountHeadExample();
        accountHeadExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<AccountHead> accountHeads = accountHeadMapper.selectByExample(accountHeadExample);
        oldJsonObject.put("accountHeads", accountHeads);
        //财务单据表体
        AccountItemExample accountItemExample = new AccountItemExample();
        accountItemExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<AccountItem> accountItems = accountItemMapper.selectByExample(accountItemExample);
        oldJsonObject.put("accountItems", accountItems);
        //账户信息
        AccountExample accountExample = new AccountExample();
        accountExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<Account> accounts = accountMapper.selectByExample(accountExample);
        oldJsonObject.put("accounts", accounts);
        //附件
        AttachmentExample attachmentExample = new AttachmentExample();
        attachmentExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<Attachment> attachments = attachmentMapper.selectByExample(attachmentExample);
        oldJsonObject.put("attachments", attachments);
        //仓库
        DepotExample depotExample = new DepotExample();
        depotExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<Depot> depots = depotMapper.selectByExample(depotExample);
        oldJsonObject.put("depots", depots);
        //单据表头
        DepotHeadExample depotHeadExample = new DepotHeadExample();
        depotHeadExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<DepotHead> depotHeads = depotHeadMapper.selectByExample(depotHeadExample);
        oldJsonObject.put("depotHeads", depotHeads);
        //单据表体
        DepotItemExample depotItemExample = new DepotItemExample();
        depotItemExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<DepotItem> depotItems = depotItemMapper.selectByExample(depotItemExample);
        oldJsonObject.put("depotItems", depotItems);
        //收支项目
        InOutItemExample inOutItemExample = new InOutItemExample();
        inOutItemExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<InOutItem> inOutItems = inOutItemMapper.selectByExample(inOutItemExample);
        oldJsonObject.put("inOutItems", inOutItems);
        //商品
//        MaterialExample materialExample = new MaterialExample();
//        materialExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
//        List<Material> materials = materialMapper.selectByExample(materialExample);
//        oldJsonObject.put("materials", materials);
        //商品属性
        MaterialAttributeExample materialAttributeExample = new MaterialAttributeExample();
        materialAttributeExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<MaterialAttribute> materialAttributes = materialAttributeMapper.selectByExample(materialAttributeExample);
        oldJsonObject.put("materialAttributes", materialAttributes);
        //商品类型
//        MaterialCategoryExample materialCategoryExample = new MaterialCategoryExample();
//        materialCategoryExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
//        List<MaterialCategory> materialCategories = materialCategoryMapper.selectByExample(materialCategoryExample);
//        oldJsonObject.put("materialCategories", materialCategories);
        //商品当前库存
        MaterialCurrentStockExample materialCurrentStockExample = new MaterialCurrentStockExample();
        materialCurrentStockExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<MaterialCurrentStock> materialCurrentStocks = materialCurrentStockMapper.selectByExample(materialCurrentStockExample);
        oldJsonObject.put("materialCurrentStocks", materialCurrentStocks);
//        //商品价格
        MaterialExtendExample materialExtendExample = new MaterialExtendExample();
        materialExtendExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<MaterialExtend> materialExtends = materialExtendMapper.selectByExample(materialExtendExample);
        oldJsonObject.put("materialExtends", materialExtends);
        //商品初始库存
        MaterialInitialStockExample materialInitialStockExample = new MaterialInitialStockExample();
        materialInitialStockExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<MaterialInitialStock> materialInitialStocks = materialInitialStockMapper.selectByExample(materialInitialStockExample);
        oldJsonObject.put("materialInitialStocks", materialInitialStocks);
        //促销仓库
        PromotionDepotExample promotionDepotExample = new PromotionDepotExample();
        promotionDepotExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<PromotionDepot> promotionDepots = promotionDepotMapper.selectByExample(promotionDepotExample);
        oldJsonObject.put("promotionDepots", promotionDepots);
        //赠品
        PromotionGiftExample promotionGiftExample = new PromotionGiftExample();
        promotionGiftExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<PromotionGift> promotionGifts = promotionGiftMapper.selectByExample(promotionGiftExample);
        oldJsonObject.put("promotionGifts", promotionGifts);
        //促销主表
        PromotionHeadExample promotionHeadExample = new PromotionHeadExample();
        promotionHeadExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<PromotionHead> promotionHeads = promotionHeadMapper.selectByExample(promotionHeadExample);
        oldJsonObject.put("promotionHeads", promotionHeads);
        //促销子表
        PromotionItemExample promotionItemExample = new PromotionItemExample();
        promotionItemExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<PromotionItem> promotionItems = promotionItemMapper.selectByExample(promotionItemExample);
        oldJsonObject.put("promotionItems", promotionItems);
        //促销客户
        PromotionSupplierExample promotionSupplierExample = new PromotionSupplierExample();
        promotionSupplierExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<PromotionSupplier> promotionSuppliers = promotionSupplierMapper.selectByExample(promotionSupplierExample);
        oldJsonObject.put("promotionSuppliers", promotionSuppliers);
//        //商品扩展
        MaterialPropertyExample materialPropertyExample = new MaterialPropertyExample();
        materialPropertyExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
        List<MaterialProperty> materialProperties = materialPropertyMapper.selectByExample(materialPropertyExample);
        oldJsonObject.put("materialProperties", materialProperties);
        //消息
        MsgExample msgExample = new MsgExample();
        msgExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<Msg> msgs = msgMapper.selectByExample(msgExample);
        oldJsonObject.put("msgs", msgs);
        //机构用户关系
        OrgaUserRelExample orgaUserRelExample = new OrgaUserRelExample();
        orgaUserRelExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<OrgaUserRel> orgaUserRels = orgaUserRelMapper.selectByExample(orgaUserRelExample);
        oldJsonObject.put("orgaUserRels", orgaUserRels);
        //机构表
        OrganizationExample organizationExample = new OrganizationExample();
        organizationExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<Organization> organizations = organizationMapper.selectByExample(organizationExample);
        oldJsonObject.put("organizations", organizations);
        //经手人
        PersonExample personExample = new PersonExample();
        personExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<Person> persons = personMapper.selectByExample(personExample);
        oldJsonObject.put("persons", persons);
        //返利表头
        RebateExample rebateExample = new RebateExample();
        rebateExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<Rebate> rebates = rebateMapper.selectByExample(rebateExample);
        oldJsonObject.put("rebates", rebates);
        //返利表体
        RebateItemExample rebateItemExample = new RebateItemExample();
        rebateItemExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<RebateItem> rebateItems = rebateItemMapper.selectByExample(rebateItemExample);
        oldJsonObject.put("rebateItems", rebateItems);
        //返利商品
        RebateMaterialExample rebateMaterialExample = new RebateMaterialExample();
        rebateMaterialExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<RebateMaterial> rebateMaterials = rebateMaterialMapper.selectByExample(rebateMaterialExample);
        oldJsonObject.put("rebateMaterials", rebateMaterials);
        //返利规则
        RebateRuleExample rebateRuleExample = new RebateRuleExample();
        rebateRuleExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<RebateRule> rebateRules = rebateRuleMapper.selectByExample(rebateRuleExample);
        oldJsonObject.put("rebateRules", rebateRules);
        //角色
        RoleExample roleExample = new RoleExample();
        roleExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<Role> roles = roleMapper.selectByExample(roleExample);
        oldJsonObject.put("roles", roles);
        //序列号
        SerialNumberExample serialNumberExample = new SerialNumberExample();
        serialNumberExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<SerialNumber> serialNumbers = serialNumberMapper.selectByExample(serialNumberExample);
        oldJsonObject.put("serialNumbers", serialNumbers);
        //供应商/客户
        SupplierExample supplierExample = new SupplierExample();
        supplierExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<Supplier> suppliers = supplierMapper.selectByExample(supplierExample);
        oldJsonObject.put("suppliers", suppliers);
        //系统参数
        SystemConfigExample systemConfigExample = new SystemConfigExample();
        systemConfigExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<SystemConfig> systemConfigs = systemConfigMapper.selectByExample(systemConfigExample);
        oldJsonObject.put("systemConfigs", systemConfigs);
        //租户
        TenantExample tenantExample = new TenantExample();
        tenantExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<Tenant> tenants = tenantMapper.selectByExample(tenantExample);
        oldJsonObject.put("tenants", tenants);
        //单位
        UnitExample unitExample = new UnitExample();
        unitExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<Unit> units = unitMapper.selectByExample(unitExample);
        oldJsonObject.put("units", units);
        //用户
        UserExample userExample = new UserExample();
        userExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<User> users = userMapper.selectByExample(userExample);
        oldJsonObject.put("users", users);
        //用户-角色-模块关系
        UserBusinessExample userBusinessExample = new UserBusinessExample();
        userBusinessExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<UserBusiness> userBusinesses = userBusinessMapper.selectByExample(userBusinessExample);
        oldJsonObject.put("userBusinesses", userBusinesses);
        //用户类型
        UserCategoryExample userCategoryExample = new UserCategoryExample();
        userCategoryExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<UserCategory> userCategories = userCategoryMapper.selectByExample(userCategoryExample);
        oldJsonObject.put("userCategories", userCategories);
        //审批明细
        WorkflowApproveDetailExample workflowApproveDetailExample = new WorkflowApproveDetailExample();
        workflowApproveDetailExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<WorkflowApproveDetail> workflowApproveDetails = workflowApproveDetailMapper.selectByExample(workflowApproveDetailExample);
        oldJsonObject.put("workflowApproveDetails", workflowApproveDetails);
        //配置明细
        WorkflowConfigDetailExample workflowConfigDetailExample = new WorkflowConfigDetailExample();
        workflowConfigDetailExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<WorkflowConfigDetail> workflowConfigDetails = workflowConfigDetailMapper.selectByExample(workflowConfigDetailExample);
        oldJsonObject.put("workflowConfigDetails", workflowConfigDetails);
        //配置主表
        WorkflowConfigMainExample workflowConfigMainExample = new WorkflowConfigMainExample();
        workflowConfigMainExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<WorkflowConfigMain> workflowConfigMains = workflowConfigMainMapper.selectByExample(workflowConfigMainExample);
        oldJsonObject.put("workflowConfigMains", workflowConfigMains);
        //处理详情
        WorkflowProcessDetailExample workflowProcessDetailExample = new WorkflowProcessDetailExample();
        workflowProcessDetailExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<WorkflowProcessDetail> processDetails = workflowProcessDetailMapper.selectByExample(workflowProcessDetailExample);
        oldJsonObject.put("processDetails", processDetails);
        //处理详情历史记录
        WorkflowProcessDetailHisExample workflowProcessDetailHisExample = new WorkflowProcessDetailHisExample();
        workflowProcessDetailHisExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<WorkflowProcessDetailHis> processDetailHis = workflowProcessDetailHisMapper.selectByExample(workflowProcessDetailHisExample);
        oldJsonObject.put("processDetailHis", processDetailHis);
        //钱箱金额修改记录
        CashBoxRecordExample cashBoxRecordExample = new CashBoxRecordExample();
        cashBoxRecordExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<CashBoxRecord> cashBoxRecords = cashBoxRecordMapper.selectByExample(cashBoxRecordExample);
        oldJsonObject.put("cashBoxRecords", cashBoxRecords);
        //收银员上班记录
        RetailRecordExample retailRecordExample = new RetailRecordExample();
        retailRecordExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<RetailRecord> retailRecords = retailRecordMapper.selectByExample(retailRecordExample);
        oldJsonObject.put("retailRecords", retailRecords);
        //地址信息
        AddressExample addressExample = new AddressExample();
        addressExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<Address> addresses = addressMapper.selectByExample(addressExample);
        oldJsonObject.put("addresses", addresses);
        //运输公司信息
        TransportExample transportExample = new TransportExample();
        transportExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
        List<Transport> transports = transportMapper.selectByExample(transportExample);
        oldJsonObject.put("transports", transports);
        return oldJsonObject;
    }

    public JSONObject getTaskAllocation() {
        JSONObject oldJsonObject = new JSONObject();
        List<DepotHead> depotHeads = synchronizationTaskMapperEx.selectDepotHead(tenantId);
        oldJsonObject.put("depotHeads", depotHeads);
        return oldJsonObject;
    }

    public JSONObject getTaskNewJsonObject() {
        JSONObject oldJsonObject = new JSONObject();
        //财务单据表头
        List<AccountHead> accountHeads = synchronizationTaskMapperEx.selectAccountHead(tenantId);
        oldJsonObject.put("accountHeads", accountHeads);
        //财务单据表体
        List<AccountItem> accountItems = synchronizationTaskMapperEx.selectAccountItem(tenantId);
        oldJsonObject.put("accountItems", accountItems);
        //账户信息
//        List<Account> accounts = synchronizationTaskMapperEx.selectAccount(tenantId);
//        oldJsonObject.put("accounts", accounts);
        //附件
        List<Attachment> attachments = synchronizationTaskMapperEx.selectAttachment(tenantId);
        oldJsonObject.put("attachments", attachments);
        //仓库
        List<Depot> depots = synchronizationTaskMapperEx.selectDepot(tenantId);
        oldJsonObject.put("depots", depots);
        //单据表头
        List<DepotHead> depotHeads = synchronizationTaskMapperEx.selectDepotHead(tenantId);
        oldJsonObject.put("depotHeads", depotHeads);
        //单据表体
        List<DepotItem> depotItems = synchronizationTaskMapperEx.selectDepotItem(tenantId);
        oldJsonObject.put("depotItems", depotItems);
        //收支项目
//        List<InOutItem> inOutItems = synchronizationTaskMapperEx.selectInOutItem(tenantId);
//        oldJsonObject.put("inOutItems", inOutItems);
        //商品
//        MaterialExample materialExample = new MaterialExample();
//        materialExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
//        List<Material> materials = materialMapper.selectByExample(materialExample);
//        oldJsonObject.put("materials", materials);
        //商品属性
//        List<MaterialAttribute> materialAttributes = synchronizationTaskMapperEx.selectMaterialAttribute(tenantId);
//        oldJsonObject.put("materialAttributes", materialAttributes);
        //商品类型
//        MaterialCategoryExample materialCategoryExample = new MaterialCategoryExample();
//        materialCategoryExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
//        List<MaterialCategory> materialCategories = materialCategoryMapper.selectByExample(materialCategoryExample);
//        oldJsonObject.put("materialCategories", materialCategories);
        //商品当前库存
        List<MaterialCurrentStock> materialCurrentStocks = synchronizationTaskMapperEx.selectMaterialCurrentStock(tenantId);
        oldJsonObject.put("materialCurrentStocks", materialCurrentStocks);
//        //商品价格
//        MaterialExtendExample materialExtendExample = new MaterialExtendExample();
//        materialExtendExample.createCriteria().andUploadFlagEqualTo(BusinessConstants.UPLOAD_FLAG_EXISTS);
//        List<MaterialExtend> materialExtends = materialExtendMapper.selectByExample(materialExtendExample);
//        oldJsonObject.put("materialExtends", materialExtends);
        //商品初始库存
        List<MaterialInitialStock> materialInitialStocks = synchronizationTaskMapperEx.selectMaterialInitialStock(tenantId);
        oldJsonObject.put("materialInitialStocks", materialInitialStocks);
        //促销仓库
//        List<PromotionDepot> promotionDepots = synchronizationTaskMapperEx.selectPromotionDepot(tenantId);
//        oldJsonObject.put("promotionDepots", promotionDepots);
        //赠品
//        List<PromotionGift> promotionGifts = synchronizationTaskMapperEx.selectPromotionGift(tenantId);
//        oldJsonObject.put("promotionGifts", promotionGifts);
        //促销主表
//        List<PromotionHead> promotionHeads = synchronizationTaskMapperEx.selectPromotionHead(tenantId);
//        oldJsonObject.put("promotionHeads", promotionHeads);
        //促销子表
//        List<PromotionItem> promotionItems = synchronizationTaskMapperEx.selectPromotionItem(tenantId);
//        oldJsonObject.put("promotionItems", promotionItems);
        //促销客户
//        List<PromotionSupplier> promotionSuppliers = synchronizationTaskMapperEx.selectPromotionSupplier(tenantId);
//        oldJsonObject.put("promotionSuppliers", promotionSuppliers);
//        //商品扩展
//        MaterialPropertyExample materialPropertyExample = new MaterialPropertyExample();
//        materialPropertyExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//        List<MaterialProperty> materialProperties = materialPropertyMapper.selectByExample(materialPropertyExample);
//        oldJsonObject.put("materialProperties", materialProperties);
        //消息
//        List<Msg> msgs = synchronizationTaskMapperEx.selectMsg(tenantId);
//        oldJsonObject.put("msgs", msgs);
//        //机构用户关系
//        List<OrgaUserRel> orgaUserRels = synchronizationTaskMapperEx.selectOrgaUserRel(tenantId);
//        oldJsonObject.put("orgaUserRels", orgaUserRels);
//        //机构表
//        List<Organization> organizations = synchronizationTaskMapperEx.selectOrganization(tenantId);
//        oldJsonObject.put("organizations", organizations);
        //经手人
//        List<Person> persons = synchronizationTaskMapperEx.selectPerson(tenantId);
//        oldJsonObject.put("persons", persons);
        //返利表头
//        List<Rebate> rebates = synchronizationTaskMapperEx.selectRebate(tenantId);
//        oldJsonObject.put("rebates", rebates);
//        //返利表体
//        List<RebateItem> rebateItems = synchronizationTaskMapperEx.selectRebateItem(tenantId);
//        oldJsonObject.put("rebateItems", rebateItems);
//        //返利商品
//        List<RebateMaterial> rebateMaterials = synchronizationTaskMapperEx.selectRebateMaterial(tenantId);
//        oldJsonObject.put("rebateMaterials", rebateMaterials);
//        //返利规则
//        List<RebateRule> rebateRules = synchronizationTaskMapperEx.selectRebateRule(tenantId);
//        oldJsonObject.put("rebateRules", rebateRules);
        //角色
        List<Role> roles = synchronizationTaskMapperEx.selectRole(tenantId);
        oldJsonObject.put("roles", roles);
        //序列号
        List<SerialNumber> serialNumbers = synchronizationTaskMapperEx.selectSerialNumber(tenantId);
        oldJsonObject.put("serialNumbers", serialNumbers);
        //供应商/客户
//        List<Supplier> suppliers = synchronizationTaskMapperEx.selectSupplier(tenantId, "客户");
//        oldJsonObject.put("suppliers", suppliers);
        //系统参数
        List<SystemConfig> systemConfigs = synchronizationTaskMapperEx.selectSystemConfig(tenantId);
        oldJsonObject.put("systemConfigs", systemConfigs);
        //租户
        List<Tenant> tenants = synchronizationTaskMapperEx.selectTenant(tenantId);
        oldJsonObject.put("tenants", tenants);
        //单位
//        List<Unit> units = synchronizationTaskMapperEx.selectUnit(tenantId);
//        oldJsonObject.put("units", units);
        //用户
        List<User> users = synchronizationTaskMapperEx.selectUser(tenantId);
        oldJsonObject.put("users", users);
        //用户-角色-模块关系
        List<UserBusiness> userBusinesses = synchronizationTaskMapperEx.selectUserBusiness(tenantId);
        oldJsonObject.put("userBusinesses", userBusinesses);
        //用户类型
//        List<UserCategory> userCategories = synchronizationTaskMapperEx.selectUserCategory(tenantId);
//        oldJsonObject.put("userCategories", userCategories);
        //审批明细
        List<WorkflowApproveDetail> workflowApproveDetails = synchronizationTaskMapperEx.selectWorkflowApproveDetail(tenantId);
        oldJsonObject.put("workflowApproveDetails", workflowApproveDetails);
        //配置明细
        List<WorkflowConfigDetail> workflowConfigDetails = synchronizationTaskMapperEx.selectWorkflowConfigDetail(tenantId);
        oldJsonObject.put("workflowConfigDetails", workflowConfigDetails);
        //配置主表
        List<WorkflowConfigMain> workflowConfigMains = synchronizationTaskMapperEx.selectWorkflowConfigMain(tenantId);
        oldJsonObject.put("workflowConfigMains", workflowConfigMains);
        //处理详情
        List<WorkflowProcessDetail> processDetails = synchronizationTaskMapperEx.selectWorkflowProcessDetail(tenantId);
        oldJsonObject.put("processDetails", processDetails);
        //处理详情历史记录
        List<WorkflowProcessDetailHis> processDetailHis = synchronizationTaskMapperEx.selectWorkflowProcessDetailHis(tenantId);
        oldJsonObject.put("processDetailHis", processDetailHis);
        //钱箱金额修改记录
//        List<CashBoxRecord> cashBoxRecords = synchronizationTaskMapperEx.selectCashBoxRecord(tenantId);
//        oldJsonObject.put("cashBoxRecords", cashBoxRecords);
//        //收银员上班记录
//        List<RetailRecord> retailRecords = synchronizationTaskMapperEx.selectRetailRecord(tenantId);
//        oldJsonObject.put("retailRecords", retailRecords);
//        //地址信息
//        List<Address> addresses = synchronizationTaskMapperEx.selectAddress(tenantId);
//        oldJsonObject.put("addresses", addresses);
//        //运输公司信息
//        List<Transport> transports = synchronizationTaskMapperEx.selectTransport(tenantId);
//        oldJsonObject.put("transports", transports);
        return oldJsonObject;
    }

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    public void updateNewJsonUploadFlag(JSONObject newJsonObject) {
        try {
            //财务单据表头
            List<String> newAccountHeads = JSONObject.parseArray(newJsonObject.getJSONArray("accountHeads").toJSONString(), AccountHead.class)
                    .stream()
                    .map(AccountHead::getId)
                    .collect(Collectors.toList());
            if (newAccountHeads.size() > 0) {
                AccountHead entity = new AccountHead();
                entity.setUploadFlag("1");
                AccountHeadExample example = new AccountHeadExample();
                example.createCriteria().andIdIn(newAccountHeads);
                accountHeadMapper.updateByExampleSelective(entity, example);
            }
            //财务单据表体
            List<String> newAccountItems = JSONObject.parseArray(newJsonObject.getJSONArray("accountItems").toJSONString(), AccountItem.class)
                    .stream()
                    .map(AccountItem::getId)
                    .collect(Collectors.toList());
            if (newAccountItems.size() > 0) {
                AccountItem entity = new AccountItem();
                entity.setUploadFlag("1");
                AccountItemExample example = new AccountItemExample();
                example.createCriteria().andIdIn(newAccountItems);
                accountItemMapper.updateByExampleSelective(entity, example);
            }
            //账户信息
            List<String> newAccounts = JSONObject.parseArray(newJsonObject.getJSONArray("accounts").toJSONString(), Account.class)
                    .stream()
                    .map(Account::getId)
                    .collect(Collectors.toList());
            if (newAccounts.size() > 0) {
                Account entity = new Account();
                entity.setUploadFlag("1");
                AccountExample example = new AccountExample();
                example.createCriteria().andIdIn(newAccounts);
                accountMapper.updateByExampleSelective(entity, example);
            }
            //附件
            List<String> newAttachments = JSONObject.parseArray(newJsonObject.getJSONArray("attachments").toJSONString(), Attachment.class)
                    .stream()
                    .map(Attachment::getId)
                    .collect(Collectors.toList());
            if (newAttachments.size() > 0) {
                Attachment entity = new Attachment();
                entity.setUploadFlag("1");
                AttachmentExample example = new AttachmentExample();
                example.createCriteria().andIdIn(newAttachments);
                attachmentMapper.updateByExampleSelective(entity, example);
            }
            //仓库
            List<String> newDepots = JSONObject.parseArray(newJsonObject.getJSONArray("depots").toJSONString(), Depot.class)
                    .stream()
                    .map(Depot::getId)
                    .collect(Collectors.toList());
            if (newDepots.size() > 0) {
                Depot entity = new Depot();
                entity.setUploadFlag("1");
                DepotExample example = new DepotExample();
                example.createCriteria().andIdIn(newDepots);
                depotMapper.updateByExampleSelective(entity, example);
            }
            //单据表头
            List<String> newDepotHeads = JSONObject.parseArray(newJsonObject.getJSONArray("depotHeads").toJSONString(), DepotHead.class)
                    .stream()
                    .map(DepotHead::getId)
                    .collect(Collectors.toList());
            if (newDepotHeads.size() > 0) {
                DepotHead entity = new DepotHead();
                entity.setUploadFlag("1");
                DepotHeadExample example = new DepotHeadExample();
                example.createCriteria().andIdIn(newDepotHeads);
                depotHeadMapper.updateByExampleSelective(entity, example);
            }
            //单据表体
            List<String> newDepotItems = JSONObject.parseArray(newJsonObject.getJSONArray("depotItems").toJSONString(), DepotItem.class)
                    .stream()
                    .map(DepotItem::getId)
                    .collect(Collectors.toList());
            if (newDepotItems.size() > 0) {
                DepotItem entity = new DepotItem();
                entity.setUploadFlag("1");
                DepotItemExample example = new DepotItemExample();
                example.createCriteria().andIdIn(newDepotItems);
                depotItemMapper.updateByExampleSelective(entity, example);
            }
            //收支项目
            List<String> newInOutItems = JSONObject.parseArray(newJsonObject.getJSONArray("inOutItems").toJSONString(), InOutItem.class)
                    .stream()
                    .map(InOutItem::getId)
                    .collect(Collectors.toList());
            if (newInOutItems.size() > 0) {
                InOutItem entity = new InOutItem();
                entity.setUploadFlag("1");
                InOutItemExample example = new InOutItemExample();
                example.createCriteria().andIdIn(newInOutItems);
                inOutItemMapper.updateByExampleSelective(entity, example);
            }
            //商品
            List<String> newMaterials = JSONObject.parseArray(newJsonObject.getJSONArray("materials").toJSONString(), Material.class)
                    .stream()
                    .map(Material::getId)
                    .collect(Collectors.toList());
            if (newMaterials.size() > 0) {
                Material entity = new Material();
                entity.setUploadFlag("1");
                MaterialExample example = new MaterialExample();
                example.createCriteria().andIdIn(newMaterials);
                materialMapper.updateByExampleSelective(entity, example);
            }
            //商品属性
            List<String> newMaterialAttributes = JSONObject.parseArray(newJsonObject.getJSONArray("materialAttributes").toJSONString(), MaterialAttribute.class)
                    .stream()
                    .map(MaterialAttribute::getId)
                    .collect(Collectors.toList());
            if (newMaterialAttributes.size() > 0) {
                MaterialAttribute entity = new MaterialAttribute();
                entity.setUploadFlag("1");
                MaterialAttributeExample example = new MaterialAttributeExample();
                example.createCriteria().andIdIn(newMaterialAttributes);
                materialAttributeMapper.updateByExampleSelective(entity, example);
            }
            //商品类型
            List<String> newMaterialCategories = JSONObject.parseArray(newJsonObject.getJSONArray("materialCategories").toJSONString(), MaterialCategory.class)
                    .stream()
                    .map(MaterialCategory::getId)
                    .collect(Collectors.toList());
            if (newMaterialCategories.size() > 0) {
                MaterialCategory entity = new MaterialCategory();
                entity.setUploadFlag("1");
                MaterialCategoryExample example = new MaterialCategoryExample();
                example.createCriteria().andIdIn(newMaterialCategories);
                materialCategoryMapper.updateByExampleSelective(entity, example);
            }
            //商品当前库存
            List<String> newMaterialCurrentStocks = JSONObject.parseArray(newJsonObject.getJSONArray("materialCurrentStocks").toJSONString(), MaterialCurrentStock.class)
                    .stream()
                    .map(MaterialCurrentStock::getId)
                    .collect(Collectors.toList());
            if (newMaterialCurrentStocks.size() > 0) {
                MaterialCurrentStock entity = new MaterialCurrentStock();
                entity.setUploadFlag("1");
                MaterialCurrentStockExample example = new MaterialCurrentStockExample();
                example.createCriteria().andIdIn(newMaterialCurrentStocks);
                materialCurrentStockMapper.updateByExampleSelective(entity, example);
            }
            //商品价格
            List<String> newMaterialExtends = JSONObject.parseArray(newJsonObject.getJSONArray("materialExtends").toJSONString(), MaterialExtend.class)
                    .stream()
                    .map(MaterialExtend::getId)
                    .collect(Collectors.toList());
            if (newMaterialExtends.size() > 0) {
                MaterialExtend entity = new MaterialExtend();
                entity.setUploadFlag("1");
                MaterialExtendExample example = new MaterialExtendExample();
                example.createCriteria().andIdIn(newMaterialExtends);
                materialExtendMapper.updateByExampleSelective(entity, example);
            }

            //商品初始库存
            List<String> newMaterialInitialStocks = JSONObject.parseArray(newJsonObject.getJSONArray("materialInitialStocks").toJSONString(), MaterialInitialStock.class)
                    .stream()
                    .map(MaterialInitialStock::getId)
                    .collect(Collectors.toList());
            if (newMaterialInitialStocks.size() > 0) {
                MaterialInitialStock entity = new MaterialInitialStock();
                entity.setUploadFlag("1");
                MaterialInitialStockExample example = new MaterialInitialStockExample();
                example.createCriteria().andIdIn(newMaterialInitialStocks);
                materialInitialStockMapper.updateByExampleSelective(entity, example);
            }
            //促销仓库
            List<String> newPromotionDepots = JSONObject.parseArray(newJsonObject.getJSONArray("promotionDepots").toJSONString(), PromotionDepot.class)
                    .stream()
                    .map(PromotionDepot::getId)
                    .collect(Collectors.toList());
            if (newPromotionDepots.size() > 0) {
                PromotionDepot entity = new PromotionDepot();
                entity.setUploadFlag("1");
                PromotionDepotExample example = new PromotionDepotExample();
                example.createCriteria().andIdIn(newPromotionDepots);
                promotionDepotMapper.updateByExampleSelective(entity, example);
            }
            //赠品
            List<String> newPromotionGifts = JSONObject.parseArray(newJsonObject.getJSONArray("promotionGifts").toJSONString(), PromotionGift.class)
                    .stream()
                    .map(PromotionGift::getId)
                    .collect(Collectors.toList());
            if (newPromotionGifts.size() > 0) {
                PromotionGift entity = new PromotionGift();
                entity.setUploadFlag("1");
                PromotionGiftExample example = new PromotionGiftExample();
                example.createCriteria().andIdIn(newPromotionGifts);
                promotionGiftMapper.updateByExampleSelective(entity, example);
            }
            //促销主表
            List<String> newPromotionHeads = JSONObject.parseArray(newJsonObject.getJSONArray("promotionHeads").toJSONString(), PromotionHead.class)
                    .stream()
                    .map(PromotionHead::getId)
                    .collect(Collectors.toList());
            if (newPromotionHeads.size() > 0) {
                PromotionHead entity = new PromotionHead();
                entity.setUploadFlag("1");
                PromotionHeadExample example = new PromotionHeadExample();
                example.createCriteria().andIdIn(newPromotionHeads);
                promotionHeadMapper.updateByExampleSelective(entity, example);
            }
            //促销子表
            List<String> newPromotionItems = JSONObject.parseArray(newJsonObject.getJSONArray("promotionItems").toJSONString(), PromotionItem.class)
                    .stream()
                    .map(PromotionItem::getId)
                    .collect(Collectors.toList());
            if (newPromotionItems.size() > 0) {
                PromotionItem entity = new PromotionItem();
                entity.setUploadFlag("1");
                PromotionItemExample example = new PromotionItemExample();
                example.createCriteria().andIdIn(newPromotionItems);
                promotionItemMapper.updateByExampleSelective(entity, example);
            }
            //促销客户
            List<String> newPromotionSuppliers = JSONObject.parseArray(newJsonObject.getJSONArray("promotionSuppliers").toJSONString(), PromotionSupplier.class)
                    .stream()
                    .map(PromotionSupplier::getId)
                    .collect(Collectors.toList());
            if (newPromotionSuppliers.size() > 0) {
                PromotionSupplier entity = new PromotionSupplier();
                entity.setUploadFlag("1");
                PromotionSupplierExample example = new PromotionSupplierExample();
                example.createCriteria().andIdIn(newPromotionSuppliers);
                promotionSupplierMapper.updateByExampleSelective(entity, example);
            }
//            //商品扩展
            List<String> newMaterialProperties = JSONObject.parseArray(newJsonObject.getJSONArray("materialProperties").toJSONString(), MaterialProperty.class)
                    .stream()
                    .map(MaterialProperty::getId)
                    .collect(Collectors.toList());
            if (newMaterialProperties.size() > 0) {
                MaterialProperty entity = new MaterialProperty();
                entity.setUploadFlag("1");
                MaterialPropertyExample example = new MaterialPropertyExample();
                example.createCriteria().andIdIn(newMaterialProperties);
                materialPropertyMapper.updateByExampleSelective(entity, example);
            }
            //消息
            List<String> newMsgs = JSONObject.parseArray(newJsonObject.getJSONArray("msgs").toJSONString(), Msg.class)
                    .stream()
                    .map(Msg::getId)
                    .collect(Collectors.toList());
            if (newMsgs.size() > 0) {
                Msg entity = new Msg();
                entity.setUploadFlag("1");
                MsgExample example = new MsgExample();
                example.createCriteria().andIdIn(newMsgs);
                msgMapper.updateByExampleSelective(entity, example);
            }
            //机构用户关系
            List<String> newOrgaUserRels = JSONObject.parseArray(newJsonObject.getJSONArray("orgaUserRels").toJSONString(), OrgaUserRel.class)
                    .stream()
                    .map(OrgaUserRel::getId)
                    .collect(Collectors.toList());
            if (newOrgaUserRels.size() > 0) {
                OrgaUserRel entity = new OrgaUserRel();
                entity.setUploadFlag("1");
                OrgaUserRelExample example = new OrgaUserRelExample();
                example.createCriteria().andIdIn(newOrgaUserRels);
                orgaUserRelMapper.updateByExampleSelective(entity, example);
            }
            //机构表
            List<String> newOrganizations = JSONObject.parseArray(newJsonObject.getJSONArray("organizations").toJSONString(), Organization.class)
                    .stream()
                    .map(Organization::getId)
                    .collect(Collectors.toList());
            if (newOrganizations.size() > 0) {
                Organization entity = new Organization();
                entity.setUploadFlag("1");
                OrganizationExample example = new OrganizationExample();
                example.createCriteria().andIdIn(newOrganizations);
                organizationMapper.updateByExampleSelective(entity, example);
            }
            //经手人
            List<String> newPersons = JSONObject.parseArray(newJsonObject.getJSONArray("persons").toJSONString(), Person.class)
                    .stream()
                    .map(Person::getId)
                    .collect(Collectors.toList());
            if (newPersons.size() > 0) {
                Person entity = new Person();
                entity.setUploadFlag("1");
                PersonExample example = new PersonExample();
                example.createCriteria().andIdIn(newPersons);
                personMapper.updateByExampleSelective(entity, example);
            }
            //返利表头
            List<String> newRebates = JSONObject.parseArray(newJsonObject.getJSONArray("rebates").toJSONString(), Rebate.class)
                    .stream()
                    .map(Rebate::getId)
                    .collect(Collectors.toList());
            if (newRebates.size() > 0) {
                Rebate entity = new Rebate();
                entity.setUploadFlag("1");
                RebateExample example = new RebateExample();
                example.createCriteria().andIdIn(newRebates);
                rebateMapper.updateByExampleSelective(entity, example);
            }
            //返利表体
            List<String> newRebateItems = JSONObject.parseArray(newJsonObject.getJSONArray("rebateItems").toJSONString(), RebateItem.class)
                    .stream()
                    .map(RebateItem::getId)
                    .collect(Collectors.toList());
            if (newRebateItems.size() > 0) {
                RebateItem entity = new RebateItem();
                entity.setUploadFlag("1");
                RebateItemExample example = new RebateItemExample();
                example.createCriteria().andIdIn(newRebateItems);
                rebateItemMapper.updateByExampleSelective(entity, example);
            }
            //返利商品
            List<String> newRebateMaterials = JSONObject.parseArray(newJsonObject.getJSONArray("rebateMaterials").toJSONString(), RebateMaterial.class)
                    .stream()
                    .map(RebateMaterial::getId)
                    .collect(Collectors.toList());
            if (newRebateMaterials.size() > 0) {
                RebateMaterial entity = new RebateMaterial();
                entity.setUploadFlag("1");
                RebateMaterialExample example = new RebateMaterialExample();
                example.createCriteria().andIdIn(newRebateMaterials);
                rebateMaterialMapper.updateByExampleSelective(entity, example);
            }
            //返利规则
            List<String> newRebateRules = JSONObject.parseArray(newJsonObject.getJSONArray("rebateRules").toJSONString(), RebateRule.class)
                    .stream()
                    .map(RebateRule::getId)
                    .collect(Collectors.toList());
            if (newRebateRules.size() > 0) {
                RebateRule entity = new RebateRule();
                entity.setUploadFlag("1");
                RebateRuleExample example = new RebateRuleExample();
                example.createCriteria().andIdIn(newRebateRules);
                rebateRuleMapper.updateByExampleSelective(entity, example);
            }
            //角色
            List<String> newRoles = JSONObject.parseArray(newJsonObject.getJSONArray("roles").toJSONString(), Role.class)
                    .stream()
                    .map(Role::getId)
                    .collect(Collectors.toList());
            if (newRoles.size() > 0) {
                Role entity = new Role();
                entity.setUploadFlag("1");
                RoleExample example = new RoleExample();
                example.createCriteria().andIdIn(newRoles);
                roleMapper.updateByExampleSelective(entity, example);
            }
            //序列号
            List<String> newSerialNumbers = JSONObject.parseArray(newJsonObject.getJSONArray("serialNumbers").toJSONString(), SerialNumber.class)
                    .stream()
                    .map(SerialNumber::getId)
                    .collect(Collectors.toList());
            if (newSerialNumbers.size() > 0) {
                SerialNumber entity = new SerialNumber();
                entity.setUploadFlag("1");
                SerialNumberExample example = new SerialNumberExample();
                example.createCriteria().andIdIn(newSerialNumbers);
                serialNumberMapper.updateByExampleSelective(entity, example);
            }
            //供应商/客户
            List<String> newSuppliers = JSONObject.parseArray(newJsonObject.getJSONArray("suppliers").toJSONString(), Supplier.class)
                    .stream()
                    .map(Supplier::getId)
                    .collect(Collectors.toList());
            if (newSuppliers.size() > 0) {
                Supplier entity = new Supplier();
                entity.setUploadFlag("1");
                SupplierExample example = new SupplierExample();
                example.createCriteria().andIdIn(newSuppliers);
                supplierMapper.updateByExampleSelective(entity, example);
            }
            //系统参数
            List<String> newSystemConfigs = JSONObject.parseArray(newJsonObject.getJSONArray("systemConfigs").toJSONString(), SystemConfig.class)
                    .stream()
                    .map(SystemConfig::getId)
                    .collect(Collectors.toList());
            if (newSystemConfigs.size() > 0) {
                SystemConfig entity = new SystemConfig();
                entity.setUploadFlag("1");
                SystemConfigExample example = new SystemConfigExample();
                example.createCriteria().andIdIn(newSystemConfigs);
                systemConfigMapper.updateByExampleSelective(entity, example);
            }
            //租户
            List<String> newTenants = JSONObject.parseArray(newJsonObject.getJSONArray("tenants").toJSONString(), Tenant.class)
                    .stream()
                    .map(Tenant::getId)
                    .collect(Collectors.toList());
            if (newTenants.size() > 0) {
                Tenant entity = new Tenant();
                entity.setUploadFlag("1");
                TenantExample example = new TenantExample();
                example.createCriteria().andIdIn(newTenants);
                tenantMapper.updateByExampleSelective(entity, example);
            }
            //单位
            List<String> newUnits = JSONObject.parseArray(newJsonObject.getJSONArray("units").toJSONString(), Unit.class)
                    .stream()
                    .map(Unit::getId)
                    .collect(Collectors.toList());
            if (newUnits.size() > 0) {
                Unit entity = new Unit();
                entity.setUploadFlag("1");
                UnitExample example = new UnitExample();
                example.createCriteria().andIdIn(newUnits);
                unitMapper.updateByExampleSelective(entity, example);
            }
            //用户
            List<String> newUsers = JSONObject.parseArray(newJsonObject.getJSONArray("users").toJSONString(), User.class)
                    .stream()
                    .map(User::getId)
                    .collect(Collectors.toList());
            if (newUsers.size() > 0) {
                User entity = new User();
                entity.setUploadFlag("1");
                UserExample example = new UserExample();
                example.createCriteria().andIdIn(newUsers);
                userMapper.updateByExampleSelective(entity, example);
            }
            //用户-角色-模块关系
            List<String> newUserBusinesses = JSONObject.parseArray(newJsonObject.getJSONArray("userBusinesses").toJSONString(), UserBusiness.class)
                    .stream()
                    .map(UserBusiness::getId)
                    .collect(Collectors.toList());
            if (newUserBusinesses.size() > 0) {
                UserBusiness entity = new UserBusiness();
                entity.setUploadFlag("1");
                UserBusinessExample example = new UserBusinessExample();
                example.createCriteria().andIdIn(newUserBusinesses);
                userBusinessMapper.updateByExampleSelective(entity, example);
            }
            //用户类型
            List<String> newUserCategories = JSONObject.parseArray(newJsonObject.getJSONArray("userCategories").toJSONString(), UserCategory.class)
                    .stream()
                    .map(UserCategory::getId)
                    .collect(Collectors.toList());
            if (newUserCategories.size() > 0) {
                UserCategory entity = new UserCategory();
                entity.setUploadFlag("1");
                UserCategoryExample example = new UserCategoryExample();
                example.createCriteria().andIdIn(newUserCategories);
                userCategoryMapper.updateByExampleSelective(entity, example);
            }
            //审批明细
            List<String> newWorkflowApproveDetails = JSONObject.parseArray(newJsonObject.getJSONArray("workflowApproveDetails").toJSONString(), WorkflowApproveDetail.class)
                    .stream()
                    .map(WorkflowApproveDetail::getId)
                    .collect(Collectors.toList());
            if (newWorkflowApproveDetails.size() > 0) {
                WorkflowApproveDetail entity = new WorkflowApproveDetail();
                entity.setUploadFlag("1");
                WorkflowApproveDetailExample example = new WorkflowApproveDetailExample();
                example.createCriteria().andIdIn(newWorkflowApproveDetails);
                workflowApproveDetailMapper.updateByExampleSelective(entity, example);
            }
            //配置明细
            List<String> newWorkflowConfigDetails = JSONObject.parseArray(newJsonObject.getJSONArray("workflowConfigDetails").toJSONString(), WorkflowConfigDetail.class)
                    .stream()
                    .map(WorkflowConfigDetail::getId)
                    .collect(Collectors.toList());
            if (newWorkflowConfigDetails.size() > 0) {
                WorkflowConfigDetail entity = new WorkflowConfigDetail();
                entity.setUploadFlag("1");
                WorkflowConfigDetailExample example = new WorkflowConfigDetailExample();
                example.createCriteria().andIdIn(newWorkflowConfigDetails);
                workflowConfigDetailMapper.updateByExampleSelective(entity, example);
            }
            //配置主表
            List<String> newWorkflowConfigMains = JSONObject.parseArray(newJsonObject.getJSONArray("workflowConfigMains").toJSONString(), WorkflowConfigMain.class)
                    .stream()
                    .map(WorkflowConfigMain::getId)
                    .collect(Collectors.toList());
            if (newWorkflowConfigMains.size() > 0) {
                WorkflowConfigMain entity = new WorkflowConfigMain();
                entity.setUploadFlag("1");
                WorkflowConfigMainExample example = new WorkflowConfigMainExample();
                example.createCriteria().andIdIn(newWorkflowConfigMains);
                workflowConfigMainMapper.updateByExampleSelective(entity, example);
            }
            //处理详情
            List<String> newProcessDetails = JSONObject.parseArray(newJsonObject.getJSONArray("processDetails").toJSONString(), WorkflowProcessDetail.class)
                    .stream()
                    .map(WorkflowProcessDetail::getId)
                    .collect(Collectors.toList());
            if (newProcessDetails.size() > 0) {
                WorkflowProcessDetail entity = new WorkflowProcessDetail();
                entity.setUploadFlag("1");
                WorkflowProcessDetailExample example = new WorkflowProcessDetailExample();
                example.createCriteria().andIdIn(newProcessDetails);
                workflowProcessDetailMapper.updateByExampleSelective(entity, example);
            }
            //处理详情历史记录
            List<String> newProcessDetailHis = JSONObject.parseArray(newJsonObject.getJSONArray("processDetailHis").toJSONString(), WorkflowProcessDetailHis.class)
                    .stream()
                    .map(WorkflowProcessDetailHis::getId)
                    .collect(Collectors.toList());
            if (newProcessDetailHis.size() > 0) {
                WorkflowProcessDetailHis entity = new WorkflowProcessDetailHis();
                entity.setUploadFlag("1");
                WorkflowProcessDetailHisExample example = new WorkflowProcessDetailHisExample();
                example.createCriteria().andIdIn(newProcessDetailHis);
                workflowProcessDetailHisMapper.updateByExampleSelective(entity, example);
            }
            //钱箱金额修改记录
            List<String> newCashBoxRecords = JSONObject.parseArray(newJsonObject.getJSONArray("cashBoxRecords").toJSONString(), CashBoxRecord.class)
                    .stream()
                    .map(CashBoxRecord::getId)
                    .collect(Collectors.toList());
            if (newCashBoxRecords.size() > 0) {
                CashBoxRecord entity = new CashBoxRecord();
                entity.setUploadFlag("1");
                CashBoxRecordExample example = new CashBoxRecordExample();
                example.createCriteria().andIdIn(newCashBoxRecords);
                cashBoxRecordMapper.updateByExampleSelective(entity, example);
            }
            //收银员上班记录
            List<String> newRetailRecords = JSONObject.parseArray(newJsonObject.getJSONArray("retailRecords").toJSONString(), RetailRecord.class)
                    .stream()
                    .map(RetailRecord::getId)
                    .collect(Collectors.toList());
            if (newRetailRecords.size() > 0) {
                RetailRecord entity = new RetailRecord();
                entity.setUploadFlag("1");
                RetailRecordExample example = new RetailRecordExample();
                example.createCriteria().andIdIn(newRetailRecords);
                retailRecordMapper.updateByExampleSelective(entity, example);
            }
        } catch (Exception e) {
            JshException.writeFail(logger, e, this.getLanCode());
        }

    }

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    public void updateAllocationUploadFlag(JSONObject newJsonObject) {
        try {
            //附件
            Map<String, List<Attachment>> attachmentMap = JSONObject.parseObject(newJsonObject.getJSONObject("attachmentMap").toJSONString())
                    .entrySet().stream()
                    .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), Attachment.class)));
            for (List<Attachment> list : attachmentMap.values()) {
                List<String> ids = list.stream()
                        .map(Attachment::getId)
                        .collect(Collectors.toList());
                if (ids.size() > 0) {
                    synchronizationTaskMapperEx.updateAttachment(ids);
                }
            }
            JSONArray applyDepotHeadJSON = newJsonObject.getJSONArray("applyDepotHead");
            if (null != applyDepotHeadJSON && applyDepotHeadJSON.size() > 0) {
                //单据表头
                List<String> applyDepotHead = JSONObject.parseArray(newJsonObject.getJSONArray("applyDepotHead").toJSONString(), DepotHead.class)
                        .stream()
                        .map(DepotHead::getId)
                        .collect(Collectors.toList());
                if (applyDepotHead.size() > 0) {
                    synchronizationTaskMapperEx.updateDepotHead(applyDepotHead);
                }
                //单据表体
                Map<String, List<DepotItem>> applyDepotMap = JSONObject.parseObject(newJsonObject.getJSONObject("applyDepotMap").toJSONString())
                        .entrySet().stream()
                        .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), DepotItem.class)));
                for (List<DepotItem> list : applyDepotMap.values()) {
                    List<String> ids = list.stream()
                            .map(DepotItem::getId)
                            .collect(Collectors.toList());
                    if (ids.size() > 0) {
                        synchronizationTaskMapperEx.updateDepotItem(ids);
                    }
                }
            }

            JSONArray deliveryDepotHeadJSON = newJsonObject.getJSONArray("deliveryDepotHead");
            if (null != deliveryDepotHeadJSON && deliveryDepotHeadJSON.size() > 0) {
                //单据表头
                List<String> deliveryDepotHead = JSONObject.parseArray(newJsonObject.getJSONArray("deliveryDepotHead").toJSONString(), DepotHead.class)
                        .stream()
                        .map(DepotHead::getId)
                        .collect(Collectors.toList());
                if (deliveryDepotHead.size() > 0) {
                    synchronizationTaskMapperEx.updateDepotHead(deliveryDepotHead);
                }
                //单据表体
                Map<String, List<DepotItem>> deliveryDepotMap = JSONObject.parseObject(newJsonObject.getJSONObject("deliveryDepotMap").toJSONString())
                        .entrySet().stream()
                        .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), DepotItem.class)));
                for (List<DepotItem> list : deliveryDepotMap.values()) {
                    List<String> ids = list.stream()
                            .map(DepotItem::getId)
                            .collect(Collectors.toList());
                    if (ids.size() > 0) {
                        synchronizationTaskMapperEx.updateDepotItem(ids);
                    }
                }
            }

            JSONArray acceptanceDepotHeadJSON = newJsonObject.getJSONArray("acceptanceDepotHead");
            if (null != acceptanceDepotHeadJSON && acceptanceDepotHeadJSON.size() > 0) {
                //单据表头
                List<String> acceptanceDepotHead = JSONObject.parseArray(newJsonObject.getJSONArray("acceptanceDepotHead").toJSONString(), DepotHead.class)
                        .stream()
                        .map(DepotHead::getId)
                        .collect(Collectors.toList());
                if (acceptanceDepotHead.size() > 0) {
                    synchronizationTaskMapperEx.updateDepotHead(acceptanceDepotHead);
                }
                //单据表体
                Map<String, List<DepotItem>> acceptanceDepotMap = JSONObject.parseObject(newJsonObject.getJSONObject("acceptanceDepotMap").toJSONString())
                        .entrySet().stream()
                        .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), DepotItem.class)));
                for (List<DepotItem> list : acceptanceDepotMap.values()) {
                    List<String> ids = list.stream()
                            .map(DepotItem::getId)
                            .collect(Collectors.toList());
                    if (ids.size() > 0) {
                        synchronizationTaskMapperEx.updateDepotItem(ids);
                    }
                }
            }

            JSONArray stockInDepotHeadJSON = newJsonObject.getJSONArray("stockInDepotHead");
            if (null != stockInDepotHeadJSON && stockInDepotHeadJSON.size() > 0) {
                //单据表头
                List<String> stockInDepotHead = JSONObject.parseArray(newJsonObject.getJSONArray("stockInDepotHead").toJSONString(), DepotHead.class)
                        .stream()
                        .map(DepotHead::getId)
                        .collect(Collectors.toList());
                if (stockInDepotHead.size() > 0) {
                    synchronizationTaskMapperEx.updateDepotHead(stockInDepotHead);
                }
                //单据表体
                Map<String, List<DepotItem>> stockInDepotMap = JSONObject.parseObject(newJsonObject.getJSONObject("stockInDepotMap").toJSONString())
                        .entrySet().stream()
                        .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), DepotItem.class)));
                for (List<DepotItem> list : stockInDepotMap.values()) {
                    List<String> ids = list.stream()
                            .map(DepotItem::getId)
                            .collect(Collectors.toList());
                    if (ids.size() > 0) {
                        synchronizationTaskMapperEx.updateDepotItem(ids);
                    }
                }
            }
            JSONArray purchaseDepotHeadJSON = newJsonObject.getJSONArray("purchaseDepotHead");
            if (null != purchaseDepotHeadJSON && purchaseDepotHeadJSON.size() > 0) {
                //单据表头
                List<String> purchaseDepotHead = JSONObject.parseArray(newJsonObject.getJSONArray("purchaseDepotHead").toJSONString(), DepotHead.class)
                        .stream()
                        .map(DepotHead::getId)
                        .collect(Collectors.toList());
                if (purchaseDepotHead.size() > 0) {
                    synchronizationTaskMapperEx.updateDepotHead(purchaseDepotHead);
                }
                //单据表体
                Map<String, List<DepotItem>> purchaseDepotMap = JSONObject.parseObject(newJsonObject.getJSONObject("purchaseDepotMap").toJSONString())
                        .entrySet().stream()
                        .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), DepotItem.class)));
                for (List<DepotItem> list : purchaseDepotMap.values()) {
                    List<String> ids = list.stream()
                            .map(DepotItem::getId)
                            .collect(Collectors.toList());
                    if (ids.size() > 0) {
                        synchronizationTaskMapperEx.updateDepotItem(ids);
                    }
                }
            }


            JSONArray purchaseReturnListJSON = newJsonObject.getJSONArray("purchaseReturnList");
            if (null != purchaseReturnListJSON && purchaseReturnListJSON.size() > 0) {
                //单据表头
                List<String> purchaseReturnList = JSONObject.parseArray(newJsonObject.getJSONArray("purchaseReturnList").toJSONString(), DepotHead.class)
                        .stream()
                        .map(DepotHead::getId)
                        .collect(Collectors.toList());
                if (purchaseReturnList.size() > 0) {
                    synchronizationTaskMapperEx.updateDepotHead(purchaseReturnList);
                }
                //单据表体
                Map<String, List<DepotItem>> purchaseReturnDepotMap = JSONObject.parseObject(newJsonObject.getJSONObject("purchaseReturnDepotMap").toJSONString())
                        .entrySet().stream()
                        .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), DepotItem.class)));
                for (List<DepotItem> list : purchaseReturnDepotMap.values()) {
                    List<String> ids = list.stream()
                            .map(DepotItem::getId)
                            .collect(Collectors.toList());
                    if (ids.size() > 0) {
                        synchronizationTaskMapperEx.updateDepotItem(ids);
                    }
                }
            }
        } catch (Exception e) {
            JshException.writeFail(logger, e, "zh");
        }
    }

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    public void updatePurchaseUploadFlag(JSONObject newJsonObject) {
        try {
            //附件
            Map<String, List<Attachment>> attachmentMap = JSONObject.parseObject(newJsonObject.getJSONObject("attachmentMap").toJSONString())
                    .entrySet().stream()
                    .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), Attachment.class)));
            for (List<Attachment> list : attachmentMap.values()) {
                List<String> ids = list.stream()
                        .map(Attachment::getId)
                        .collect(Collectors.toList());
                if (ids.size() > 0) {
                    synchronizationTaskMapperEx.updateAttachment(ids);
                }
            }
            JSONArray applyDepotHeadJSON = newJsonObject.getJSONArray("applyDepotHead");
            if (null != applyDepotHeadJSON && applyDepotHeadJSON.size() > 0) {
                //单据表头
                List<String> applyDepotHead = JSONObject.parseArray(newJsonObject.getJSONArray("applyDepotHead").toJSONString(), DepotHead.class)
                        .stream()
                        .map(DepotHead::getId)
                        .collect(Collectors.toList());
                if (applyDepotHead.size() > 0) {
                    synchronizationTaskMapperEx.updateDepotHead(applyDepotHead);
                }
                //单据表体
                Map<String, List<DepotItem>> applyDepotMap = JSONObject.parseObject(newJsonObject.getJSONObject("applyDepotMap").toJSONString())
                        .entrySet().stream()
                        .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), DepotItem.class)));
                for (List<DepotItem> list : applyDepotMap.values()) {
                    List<String> ids = list.stream()
                            .map(DepotItem::getId)
                            .collect(Collectors.toList());
                    if (ids.size() > 0) {
                        synchronizationTaskMapperEx.updateDepotItem(ids);
                    }
                }
            }

            JSONArray deliveryDepotHeadJSON = newJsonObject.getJSONArray("deliveryDepotHead");
            if (null != deliveryDepotHeadJSON && deliveryDepotHeadJSON.size() > 0) {
                //单据表头
                List<String> deliveryDepotHead = JSONObject.parseArray(newJsonObject.getJSONArray("deliveryDepotHead").toJSONString(), DepotHead.class)
                        .stream()
                        .map(DepotHead::getId)
                        .collect(Collectors.toList());
                if (deliveryDepotHead.size() > 0) {
                    synchronizationTaskMapperEx.updateDepotHead(deliveryDepotHead);
                }
                //单据表体
                Map<String, List<DepotItem>> deliveryDepotMap = JSONObject.parseObject(newJsonObject.getJSONObject("deliveryDepotMap").toJSONString())
                        .entrySet().stream()
                        .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), DepotItem.class)));
                for (List<DepotItem> list : deliveryDepotMap.values()) {
                    List<String> ids = list.stream()
                            .map(DepotItem::getId)
                            .collect(Collectors.toList());
                    if (ids.size() > 0) {
                        synchronizationTaskMapperEx.updateDepotItem(ids);
                    }
                }
            }

            JSONArray acceptanceDepotHeadJSON = newJsonObject.getJSONArray("acceptanceDepotHead");
            if (null != acceptanceDepotHeadJSON && acceptanceDepotHeadJSON.size() > 0) {
                //单据表头
                List<String> acceptanceDepotHead = JSONObject.parseArray(newJsonObject.getJSONArray("acceptanceDepotHead").toJSONString(), DepotHead.class)
                        .stream()
                        .map(DepotHead::getId)
                        .collect(Collectors.toList());
                if (acceptanceDepotHead.size() > 0) {
                    synchronizationTaskMapperEx.updateDepotHead(acceptanceDepotHead);
                }
                //单据表体
                Map<String, List<DepotItem>> acceptanceDepotMap = JSONObject.parseObject(newJsonObject.getJSONObject("acceptanceDepotMap").toJSONString())
                        .entrySet().stream()
                        .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), DepotItem.class)));
                for (List<DepotItem> list : acceptanceDepotMap.values()) {
                    List<String> ids = list.stream()
                            .map(DepotItem::getId)
                            .collect(Collectors.toList());
                    if (ids.size() > 0) {
                        synchronizationTaskMapperEx.updateDepotItem(ids);
                    }
                }
            }
            JSONArray purchaseDepotHeadJSON = newJsonObject.getJSONArray("purchaseDepotHead");
            if (null != purchaseDepotHeadJSON && purchaseDepotHeadJSON.size() > 0) {
                //单据表头
                List<String> purchaseDepotHead = JSONObject.parseArray(newJsonObject.getJSONArray("purchaseDepotHead").toJSONString(), DepotHead.class)
                        .stream()
                        .map(DepotHead::getId)
                        .collect(Collectors.toList());
                if (purchaseDepotHead.size() > 0) {
                    synchronizationTaskMapperEx.updateDepotHead(purchaseDepotHead);
                }
                //单据表体
                Map<String, List<DepotItem>> purchaseDepotMap = JSONObject.parseObject(newJsonObject.getJSONObject("purchaseDepotMap").toJSONString())
                        .entrySet().stream()
                        .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), DepotItem.class)));
                for (List<DepotItem> list : purchaseDepotMap.values()) {
                    List<String> ids = list.stream()
                            .map(DepotItem::getId)
                            .collect(Collectors.toList());
                    if (ids.size() > 0) {
                        synchronizationTaskMapperEx.updateDepotItem(ids);
                    }
                }
            }

            JSONArray quotationDepotHeadJSON = newJsonObject.getJSONArray("quotationDepotHead");
            if (null != quotationDepotHeadJSON && quotationDepotHeadJSON.size() > 0) {
                //单据表头
                List<String> quotationDepotHead = JSONObject.parseArray(newJsonObject.getJSONArray("quotationDepotHead").toJSONString(), DepotHead.class)
                        .stream()
                        .map(DepotHead::getId)
                        .collect(Collectors.toList());
                if (quotationDepotHead.size() > 0) {
                    synchronizationTaskMapperEx.updateDepotHead(quotationDepotHead);
                }
                //单据表体
                Map<String, List<DepotItem>> quotationDepotMap = JSONObject.parseObject(newJsonObject.getJSONObject("quotationDepotMap").toJSONString())
                        .entrySet().stream()
                        .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), DepotItem.class)));
                for (List<DepotItem> list : quotationDepotMap.values()) {
                    List<String> ids = list.stream()
                            .map(DepotItem::getId)
                            .collect(Collectors.toList());
                    if (ids.size() > 0) {
                        synchronizationTaskMapperEx.updateDepotItem(ids);
                    }
                }
            }
            JSONArray checkDepotHeadJSON = newJsonObject.getJSONArray("checkDepotHead");
            if (null != checkDepotHeadJSON && checkDepotHeadJSON.size() > 0) {
                //单据表头
                List<String> checkDepotHead = JSONObject.parseArray(newJsonObject.getJSONArray("checkDepotHead").toJSONString(), DepotHead.class)
                        .stream()
                        .map(DepotHead::getId)
                        .collect(Collectors.toList());
                if (checkDepotHead.size() > 0) {
                    synchronizationTaskMapperEx.updateDepotHead(checkDepotHead);
                }
                //单据表体
                Map<String, List<DepotItem>> checkDepotMap = JSONObject.parseObject(newJsonObject.getJSONObject("checkDepotMap").toJSONString())
                        .entrySet().stream()
                        .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), DepotItem.class)));
                for (List<DepotItem> list : checkDepotMap.values()) {
                    List<String> ids = list.stream()
                            .map(DepotItem::getId)
                            .collect(Collectors.toList());
                    if (ids.size() > 0) {
                        synchronizationTaskMapperEx.updateDepotItem(ids);
                    }
                }
            }

            JSONArray otherDepotHeadJSON = newJsonObject.getJSONArray("otherDepotHead");
            if (null != otherDepotHeadJSON && otherDepotHeadJSON.size() > 0) {
                //单据表头
                List<String> otherDepotHead = JSONObject.parseArray(newJsonObject.getJSONArray("otherDepotHead").toJSONString(), DepotHead.class)
                        .stream()
                        .map(DepotHead::getId)
                        .collect(Collectors.toList());
                if (otherDepotHead.size() > 0) {
                    synchronizationTaskMapperEx.updateDepotHead(otherDepotHead);
                }
                //单据表体
                Map<String, List<DepotItem>> otherDepotMap = JSONObject.parseObject(newJsonObject.getJSONObject("otherDepotMap").toJSONString())
                        .entrySet().stream()
                        .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), DepotItem.class)));
                for (List<DepotItem> list : otherDepotMap.values()) {
                    List<String> ids = list.stream()
                            .map(DepotItem::getId)
                            .collect(Collectors.toList());
                    if (ids.size() > 0) {
                        synchronizationTaskMapperEx.updateDepotItem(ids);
                    }
                }
            }

        } catch (Exception e) {
            JshException.writeFail(logger, e, "zh");
        }
    }

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    public void updateTaskNewJsonUploadFlag(JSONObject newJsonObject) {
        try {
            //财务单据表头
            List<String> newAccountHeads = JSONObject.parseArray(newJsonObject.getJSONArray("accountHeads").toJSONString(), AccountHead.class)
                    .stream()
                    .map(AccountHead::getId)
                    .collect(Collectors.toList());
            if (newAccountHeads.size() > 0) {
                synchronizationTaskMapperEx.updateAccountHead(newAccountHeads);
            }
            //财务单据表体
            List<String> newAccountItems = JSONObject.parseArray(newJsonObject.getJSONArray("accountItems").toJSONString(), AccountItem.class)
                    .stream()
                    .map(AccountItem::getId)
                    .collect(Collectors.toList());
            if (newAccountItems.size() > 0) {
                synchronizationTaskMapperEx.updateAccountItem(newAccountItems);
            }
//            //账户信息
//            List<String> newAccounts = JSONObject.parseArray(newJsonObject.getJSONArray("accounts").toJSONString(), Account.class)
//                    .stream()
//                    .map(Account::getId)
//                    .collect(Collectors.toList());
//            if (newAccounts.size() > 0) {
//                synchronizationTaskMapperEx.updateAccount(newAccounts);
//            }
            //附件
            List<String> newAttachments = JSONObject.parseArray(newJsonObject.getJSONArray("attachments").toJSONString(), Attachment.class)
                    .stream()
                    .map(Attachment::getId)
                    .collect(Collectors.toList());
            if (newAttachments.size() > 0) {
                synchronizationTaskMapperEx.updateAttachment(newAttachments);
            }
            //仓库
            List<String> newDepots = JSONObject.parseArray(newJsonObject.getJSONArray("depots").toJSONString(), Depot.class)
                    .stream()
                    .map(Depot::getId)
                    .collect(Collectors.toList());
            if (newDepots.size() > 0) {
                synchronizationTaskMapperEx.updateDepot(newDepots);
            }
            //单据表头
            List<String> newDepotHeads = JSONObject.parseArray(newJsonObject.getJSONArray("depotHeads").toJSONString(), DepotHead.class)
                    .stream()
                    .map(DepotHead::getId)
                    .collect(Collectors.toList());
            if (newDepotHeads.size() > 0) {
                synchronizationTaskMapperEx.updateDepotHead(newDepotHeads);
            }
            //单据表体
            List<String> newDepotItems = JSONObject.parseArray(newJsonObject.getJSONArray("depotItems").toJSONString(), DepotItem.class)
                    .stream()
                    .map(DepotItem::getId)
                    .collect(Collectors.toList());
            if (newDepotItems.size() > 0) {
                synchronizationTaskMapperEx.updateDepotItem(newDepotItems);
            }
            //收支项目
//            List<String> newInOutItems = JSONObject.parseArray(newJsonObject.getJSONArray("inOutItems").toJSONString(), InOutItem.class)
//                    .stream()
//                    .map(InOutItem::getId)
//                    .collect(Collectors.toList());
//            if (newInOutItems.size() > 0) {
//                synchronizationTaskMapperEx.updateInOutItem(newInOutItems);
//            }
            //商品
//            List<Material> newMaterials = JSONObject.parseArray(newJsonObject.getJSONArray("materials").toJSONString(), Material.class);
            //商品属性
//            List<String> newMaterialAttributes = JSONObject.parseArray(newJsonObject.getJSONArray("materialAttributes").toJSONString(), MaterialAttribute.class)
//                    .stream()
//                    .map(MaterialAttribute::getId)
//                    .collect(Collectors.toList());
//            if (newMaterialAttributes.size() > 0) {
//                synchronizationTaskMapperEx.updateMaterialAttribute(newMaterialAttributes);
//            }
            //商品类型
//            List<MaterialCategory> newMaterialCategories = JSONObject.parseArray(newJsonObject.getJSONArray("materialCategories").toJSONString(), MaterialCategory.class);
            //商品当前库存

            List<String> newMaterialCurrentStocks = JSONObject.parseArray(newJsonObject.getJSONArray("materialCurrentStocks").toJSONString(), MaterialCurrentStock.class)
                    .stream()
                    .map(MaterialCurrentStock::getId)
                    .collect(Collectors.toList());
            if (newMaterialCurrentStocks.size() > 0) {
                synchronizationTaskMapperEx.updateMaterialCurrentStock(newMaterialCurrentStocks);
            }
            //商品价格
//            List<MaterialExtend> newMaterialExtends = JSONObject.parseArray(newJsonObject.getJSONArray("materialExtends").toJSONString(), MaterialExtend.class);

            //商品初始库存
            List<String> newMaterialInitialStocks = JSONObject.parseArray(newJsonObject.getJSONArray("materialInitialStocks").toJSONString(), MaterialInitialStock.class)
                    .stream()
                    .map(MaterialInitialStock::getId)
                    .collect(Collectors.toList());
            if (newMaterialInitialStocks.size() > 0) {
                synchronizationTaskMapperEx.updateMaterialInitialStock(newMaterialInitialStocks);
            }
//            //促销仓库
//            List<String> newPromotionDepots = JSONObject.parseArray(newJsonObject.getJSONArray("promotionDepots").toJSONString(), PromotionDepot.class)
//                    .stream()
//                    .map(PromotionDepot::getId)
//                    .collect(Collectors.toList());
//            if (newPromotionDepots.size() > 0) {
//                synchronizationTaskMapperEx.updatePromotionDepot(newPromotionDepots);
//            }
//            //赠品
//            List<String> newPromotionGifts = JSONObject.parseArray(newJsonObject.getJSONArray("promotionGifts").toJSONString(), PromotionGift.class)
//                    .stream()
//                    .map(PromotionGift::getId)
//                    .collect(Collectors.toList());
//            if (newPromotionGifts.size() > 0) {
//                synchronizationTaskMapperEx.updatePromotionGift(newPromotionGifts);
//            }
//            //促销主表
//            List<String> newPromotionHeads = JSONObject.parseArray(newJsonObject.getJSONArray("promotionHeads").toJSONString(), PromotionHead.class)
//                    .stream()
//                    .map(PromotionHead::getId)
//                    .collect(Collectors.toList());
//            if (newPromotionHeads.size() > 0) {
//                synchronizationTaskMapperEx.updatePromotionHead(newPromotionHeads);
//            }
//            //促销子表
//            List<String> newPromotionItems = JSONObject.parseArray(newJsonObject.getJSONArray("promotionItems").toJSONString(), PromotionItem.class)
//                    .stream()
//                    .map(PromotionItem::getId)
//                    .collect(Collectors.toList());
//            if (newPromotionItems.size() > 0) {
//                synchronizationTaskMapperEx.updatePromotionItem(newPromotionItems);
//            }
//            //促销客户
//            List<String> newPromotionSuppliers = JSONObject.parseArray(newJsonObject.getJSONArray("promotionSuppliers").toJSONString(), PromotionSupplier.class)
//                    .stream()
//                    .map(PromotionSupplier::getId)
//                    .collect(Collectors.toList());
//            if (newPromotionSuppliers.size() > 0) {
//                synchronizationTaskMapperEx.updatePromotionSupplier(newPromotionSuppliers);
//            }
//            //商品扩展
//            List<MaterialProperty> newMaterialProperties = JSONObject.parseArray(newJsonObject.getJSONArray("materialProperties").toJSONString(), MaterialProperty.class);
            //消息
//            List<String> newMsgs = JSONObject.parseArray(newJsonObject.getJSONArray("msgs").toJSONString(), Msg.class)
//                    .stream()
//                    .map(Msg::getId)
//                    .collect(Collectors.toList());
//            if (newMsgs.size() > 0) {
//                synchronizationTaskMapperEx.updateMsg(newMsgs);
//            }
            //机构用户关系
//            List<String> newOrgaUserRels = JSONObject.parseArray(newJsonObject.getJSONArray("orgaUserRels").toJSONString(), OrgaUserRel.class)
//                    .stream()
//                    .map(OrgaUserRel::getId)
//                    .collect(Collectors.toList());
//            if (newOrgaUserRels.size() > 0) {
//                synchronizationTaskMapperEx.updateOrgaUserRel(newOrgaUserRels);
//            }
//            //机构表
//            List<String> newOrganizations = JSONObject.parseArray(newJsonObject.getJSONArray("organizations").toJSONString(), Organization.class)
//                    .stream()
//                    .map(Organization::getId)
//                    .collect(Collectors.toList());
//            if (newOrganizations.size() > 0) {
//                synchronizationTaskMapperEx.updateOrganization(newOrganizations);
//            }
    //            //经手人
    //            List<String> newPersons = JSONObject.parseArray(newJsonObject.getJSONArray("persons").toJSONString(), Person.class)
    //                    .stream()
    //                    .map(Person::getId)
    //                    .collect(Collectors.toList());
    //            if (newPersons.size() > 0) {
    //                synchronizationTaskMapperEx.updatePerson(newPersons);
    //            }
//            //返利表头
//            List<String> newRebates = JSONObject.parseArray(newJsonObject.getJSONArray("rebates").toJSONString(), Rebate.class)
//                    .stream()
//                    .map(Rebate::getId)
//                    .collect(Collectors.toList());
//            if (newRebates.size() > 0) {
//                synchronizationTaskMapperEx.updateRebate(newRebates);
//            }
//            //返利表体
//            List<String> newRebateItems = JSONObject.parseArray(newJsonObject.getJSONArray("rebateItems").toJSONString(), RebateItem.class)
//                    .stream()
//                    .map(RebateItem::getId)
//                    .collect(Collectors.toList());
//            if (newRebateItems.size() > 0) {
//                synchronizationTaskMapperEx.updateRebateItem(newRebateItems);
//            }
//            //返利商品
//            List<String> newRebateMaterials = JSONObject.parseArray(newJsonObject.getJSONArray("rebateMaterials").toJSONString(), RebateMaterial.class)
//                    .stream()
//                    .map(RebateMaterial::getId)
//                    .collect(Collectors.toList());
//            if (newRebateMaterials.size() > 0) {
//                synchronizationTaskMapperEx.updateRebateMaterial(newRebateMaterials);
//            }
//            //返利规则
//            List<String> newRebateRules = JSONObject.parseArray(newJsonObject.getJSONArray("rebateRules").toJSONString(), RebateRule.class)
//                    .stream()
//                    .map(RebateRule::getId)
//                    .collect(Collectors.toList());
//            if (newRebateRules.size() > 0) {
//                synchronizationTaskMapperEx.updateRebateRule(newRebateRules);
//            }
            //角色
            List<String> newRoles = JSONObject.parseArray(newJsonObject.getJSONArray("roles").toJSONString(), Role.class)
                    .stream()
                    .map(Role::getId)
                    .collect(Collectors.toList());
            if (newRoles.size() > 0) {
                synchronizationTaskMapperEx.updateRole(newRoles);
            }
            //序列号
            List<String> newSerialNumbers = JSONObject.parseArray(newJsonObject.getJSONArray("serialNumbers").toJSONString(), SerialNumber.class)
                    .stream()
                    .map(SerialNumber::getId)
                    .collect(Collectors.toList());
            if (newSerialNumbers.size() > 0) {
                synchronizationTaskMapperEx.updateRole(newSerialNumbers);
            }
//            //供应商/客户
//            List<String> newSuppliers = JSONObject.parseArray(newJsonObject.getJSONArray("suppliers").toJSONString(), Supplier.class)
//                    .stream()
//                    .map(Supplier::getId)
//                    .collect(Collectors.toList());
//            if (newSuppliers.size() > 0) {
//                synchronizationTaskMapperEx.updateSupplier(newSuppliers);
//            }
            //系统参数
            List<String> newSystemConfigs = JSONObject.parseArray(newJsonObject.getJSONArray("systemConfigs").toJSONString(), SystemConfig.class)
                    .stream()
                    .map(SystemConfig::getId)
                    .collect(Collectors.toList());
            if (newSystemConfigs.size() > 0) {
                synchronizationTaskMapperEx.updateSystemConfig(newSystemConfigs);
            }
            //租户
            List<String> newTenants = JSONObject.parseArray(newJsonObject.getJSONArray("tenants").toJSONString(), Tenant.class)
                    .stream()
                    .map(Tenant::getId)
                    .collect(Collectors.toList());
            if (newTenants.size() > 0) {
                synchronizationTaskMapperEx.updateTenant(newTenants);
            }
//            //单位
//            List<String> newUnits = JSONObject.parseArray(newJsonObject.getJSONArray("units").toJSONString(), Unit.class)
//                    .stream()
//                    .map(Unit::getId)
//                    .collect(Collectors.toList());
//            if (newUnits.size() > 0) {
//                synchronizationTaskMapperEx.updateUnit(newUnits);
//            }
            //用户
            List<String> newUsers = JSONObject.parseArray(newJsonObject.getJSONArray("users").toJSONString(), User.class)
                    .stream()
                    .map(User::getId)
                    .collect(Collectors.toList());
            if (newUsers.size() > 0) {
                synchronizationTaskMapperEx.updateUser(newUsers);
            }
            //用户-角色-模块关系
            List<String> newUserBusinesses = JSONObject.parseArray(newJsonObject.getJSONArray("userBusinesses").toJSONString(), UserBusiness.class)
                    .stream()
                    .map(UserBusiness::getId)
                    .collect(Collectors.toList());
            if (newUserBusinesses.size() > 0) {
                synchronizationTaskMapperEx.updateUserBusiness(newUserBusinesses);
            }
            //用户类型
//            List<String> newUserCategories = JSONObject.parseArray(newJsonObject.getJSONArray("userCategories").toJSONString(), UserCategory.class)
//                    .stream()
//                    .map(UserCategory::getId)
//                    .collect(Collectors.toList());
//            if (newUserCategories.size() > 0) {
//                synchronizationTaskMapperEx.updateUserCategory(newUserCategories);
//            }
            //审批明细
            List<String> newWorkflowApproveDetails = JSONObject.parseArray(newJsonObject.getJSONArray("workflowApproveDetails").toJSONString(), WorkflowApproveDetail.class)
                    .stream()
                    .map(WorkflowApproveDetail::getId)
                    .collect(Collectors.toList());
            if (newWorkflowApproveDetails.size() > 0) {
                synchronizationTaskMapperEx.updateWorkflowApproveDetail(newWorkflowApproveDetails);
            }
            //配置明细
            List<String> newWorkflowConfigDetails = JSONObject.parseArray(newJsonObject.getJSONArray("workflowConfigDetails").toJSONString(), WorkflowConfigDetail.class)
                    .stream()
                    .map(WorkflowConfigDetail::getId)
                    .collect(Collectors.toList());
            if (newWorkflowConfigDetails.size() > 0) {
                synchronizationTaskMapperEx.updateWorkflowConfigDetail(newWorkflowConfigDetails);
            }
            //配置主表
            List<String> newWorkflowConfigMains = JSONObject.parseArray(newJsonObject.getJSONArray("workflowConfigMains").toJSONString(), WorkflowConfigMain.class)
                    .stream()
                    .map(WorkflowConfigMain::getId)
                    .collect(Collectors.toList());
            if (newWorkflowConfigMains.size() > 0) {
                synchronizationTaskMapperEx.updateWorkflowConfigMain(newWorkflowConfigMains);
            }
            //处理详情
            List<String> newProcessDetails = JSONObject.parseArray(newJsonObject.getJSONArray("processDetails").toJSONString(), WorkflowProcessDetail.class)
                    .stream()
                    .map(WorkflowProcessDetail::getId)
                    .collect(Collectors.toList());
            if (newProcessDetails.size() > 0) {
                synchronizationTaskMapperEx.updateWorkflowProcessDetail(newProcessDetails);
            }
            //处理详情历史记录
            List<String> newProcessDetailHis = JSONObject.parseArray(newJsonObject.getJSONArray("processDetailHis").toJSONString(), WorkflowProcessDetailHis.class)
                    .stream()
                    .map(WorkflowProcessDetailHis::getId)
                    .collect(Collectors.toList());
            if (newProcessDetailHis.size() > 0) {
                synchronizationTaskMapperEx.updateWorkflowProcessDetailHis(newProcessDetailHis);
            }
//            //钱箱金额修改记录
//            List<String> newCashBoxRecords = JSONObject.parseArray(newJsonObject.getJSONArray("cashBoxRecords").toJSONString(), CashBoxRecord.class)
//                    .stream()
//                    .map(CashBoxRecord::getId)
//                    .collect(Collectors.toList());
//            if (newCashBoxRecords.size() > 0) {
//                synchronizationTaskMapperEx.updateCashBoxRecord(newCashBoxRecords);
//            }
//            //收银员上班记录
//            List<String> newRetailRecords = JSONObject.parseArray(newJsonObject.getJSONArray("retailRecords").toJSONString(), RetailRecord.class)
//                    .stream()
//                    .map(RetailRecord::getId)
//                    .collect(Collectors.toList());
//            if (newRetailRecords.size() > 0) {
//                synchronizationTaskMapperEx.updateRetailRecord(newRetailRecords);
//            }
//            //地址信息
//            List<String> newAddress = JSONObject.parseArray(newJsonObject.getJSONArray("addresses").toJSONString(), Address.class)
//                    .stream()
//                    .map(Address::getId)
//                    .collect(Collectors.toList());
//            if (newAddress.size() > 0) {
//                synchronizationTaskMapperEx.updateAddress(newAddress);
//            }
//            //运输公司信息
//            List<String> newTransport = JSONObject.parseArray(newJsonObject.getJSONArray("transports").toJSONString(), Transport.class)
//                    .stream()
//                    .map(Transport::getId)
//                    .collect(Collectors.toList());
//            if (newTransport.size() > 0) {
//                synchronizationTaskMapperEx.updateTransport(newTransport);
//            }
        } catch (Exception e) {
            JshException.writeFail(logger, e, "zh");
        }

    }

    /**
     * @Author: wy
     * @Description: 上传分店数据到总店
     * @DateTime: 2022-08-23 17:26
     * @Params:
     * @Return
     */
    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    public void synchronization(JSONObject newJsonObject) {
        try {
            //财务单据表头
            AccountHeadExample accountHeadExample = new AccountHeadExample();
            List<AccountHead> oldAccountHeads = accountHeadMapper.selectByExample(accountHeadExample);
            List<AccountHead> newAccountHeads = JSONObject.parseArray(newJsonObject.getJSONArray("accountHeads").toJSONString(), AccountHead.class);
            for (AccountHead newAccountHead : newAccountHeads) {
                for (AccountHead oldAccountHead : oldAccountHeads) {
                    if (newAccountHead.getId().equals(oldAccountHead.getId())) {
                        accountHeadMapper.updateByPrimaryKeySelective(newAccountHead);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newAccountHead = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newAccountHead != null) {
                    accountHeadMapper.insertSelective(newAccountHead);
                }
            }

            //财务单据表体
            AccountItemExample accountItemExample = new AccountItemExample();
            List<AccountItem> oldAccountItems = accountItemMapper.selectByExample(accountItemExample);
            List<AccountItem> newAccountItems = JSONObject.parseArray(newJsonObject.getJSONArray("accountItems").toJSONString(), AccountItem.class);
            for (AccountItem newAccountItem : newAccountItems) {
                for (AccountItem oldAccountItem : oldAccountItems) {
                    if (newAccountItem.getId().equals(oldAccountItem.getId())) {
                        accountItemMapper.updateByPrimaryKeySelective(newAccountItem);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newAccountItem = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newAccountItem != null) {
                    accountItemMapper.insertSelective(newAccountItem);
                }
            }


//            //账户信息
//            AccountExample accountExample = new AccountExample();
//            List<Account> oldAccounts = accountMapper.selectByExample(accountExample);
//            List<Account> newAccounts = JSONObject.parseArray(newJsonObject.getJSONArray("accounts").toJSONString(), Account.class);
//            for (Account newAccount : newAccounts) {
//                for (Account oldAccount : oldAccounts) {
//                    if (newAccount.getId().equals(oldAccount.getId())) {
//                        accountMapper.updateByPrimaryKeySelective(newAccount);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newAccount = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newAccount != null) {
//                    accountMapper.insertSelective(newAccount);
//                }
//            }
            //附件
            AttachmentExample attachmentExample = new AttachmentExample();
            List<Attachment> oldAttachments = attachmentMapper.selectByExample(attachmentExample);
            List<Attachment> newAttachments = JSONObject.parseArray(newJsonObject.getJSONArray("attachments").toJSONString(), Attachment.class);
            for (Attachment newAttachment : newAttachments) {
                for (Attachment oldAttachment : oldAttachments) {
                    if (newAttachment.getId().equals(oldAttachment.getId())) {
                        attachmentMapper.updateByPrimaryKeySelective(newAttachment);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newAttachment = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newAttachment != null) {
                    attachmentMapper.insertSelective(newAttachment);
                }
            }
            //仓库
            DepotExample depotExample = new DepotExample();
            List<Depot> oldDepots = depotMapper.selectByExample(depotExample);
            List<Depot> newDepots = JSONObject.parseArray(newJsonObject.getJSONArray("depots").toJSONString(), Depot.class);
            for (Depot newDepot : newDepots) {
                for (Depot oldDepot : oldDepots) {
                    if (newDepot.getId().equals(oldDepot.getId())) {
                        depotMapper.updateByPrimaryKeySelective(newDepot);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newDepot = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newDepot != null) {
                    depotMapper.insertSelective(newDepot);
                }
            }
            //单据表头
//            List<DepotHead> updateDepotHeadList=new ArrayList<>();
//            List<DepotHead> insertDepotHeadList=new ArrayList<>();
//            DepotHeadExample depotHeadExample = new DepotHeadExample();
//            List<DepotHead> oldDepotHeads = depotHeadMapper.selectByExample(depotHeadExample);
//            List<DepotHead> oldDepotHeads = synchronizationTaskMapperEx.selectDepotHeadByDateSub();
            List<DepotHead> newDepotHeads = JSONObject.parseArray(newJsonObject.getJSONArray("depotHeads").toJSONString(), DepotHead.class);
//            for (DepotHead newEntity : newDepotHeads) {
//                for (DepotHead oldEntity : oldDepotHeads) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        updateDepotHeadList.add(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    insertDepotHeadList.add(newEntity);
//                }
//            }
//            if (updateDepotHeadList.size()>0){
//                depotHeadMapperEx.updateList(updateDepotHeadList);
//            }

            if (newDepotHeads.size()>0){
                List<String> collect = newDepotHeads.stream().map(DepotHead::getId).collect(Collectors.toList());
                depotHeadMapperEx.deleteByListId(collect);
                depotHeadMapperEx.insertList(newDepotHeads);
            }
            //单据表体
//            List<DepotItem> updateDepotItemList=new ArrayList<>();
//            List<DepotItem> insertDepotItemList=new ArrayList<>();
//            List<DepotItem> oldDepotItems = synchronizationTaskMapperEx.selectDepotItemDateSub();
            List<DepotItem> newDepotItems = JSONObject.parseArray(newJsonObject.getJSONArray("depotItems").toJSONString(), DepotItem.class);
//            for (DepotItem newEntity : newDepotItems) {
//                for (DepotItem oldEntity : oldDepotItems) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
////                        depotItemMapper.updateByPrimaryKeySelective(newEntity);
//                        updateDepotItemList.add(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    insertDepotItemList.add(newEntity);
//                }
//            }

//            if (updateDepotItemList.size()>0){
//                depotItemMapperEx.updateList(updateDepotItemList);
//            }
            if (newDepotItems.size()>0){
                List<String> collect = newDepotItems.stream().map(DepotItem::getId).collect(Collectors.toList());
                depotItemMapperEx.deleteByListId(collect);
                depotItemMapperEx.insertList(newDepotItems);
            }
            //收支项目
//            InOutItemExample inOutItemExample = new InOutItemExample();
//            List<InOutItem> oldInOutItems = inOutItemMapper.selectByExample(inOutItemExample);
//            List<InOutItem> newInOutItems = JSONObject.parseArray(newJsonObject.getJSONArray("inOutItems").toJSONString(), InOutItem.class);
//            for (InOutItem newEntity : newInOutItems) {
//                for (InOutItem oldEntity : oldInOutItems) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        inOutItemMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    inOutItemMapper.insertSelective(newEntity);
//                }
//            }
            //商品
//            MaterialExample materialExample = new MaterialExample();
//            List<Material> oldMaterials = materialMapper.selectByExample(materialExample);
//            List<Material> newMaterials = JSONObject.parseArray(newJsonObject.getJSONArray("materials").toJSONString(), Material.class);
//            for (Material newEntity : newMaterials) {
//                for (Material oldEntity : oldMaterials) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        materialMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    materialMapper.insertSelective(newEntity);
//                }
//            }
//            //商品属性
//            MaterialAttributeExample materialAttributeExample = new MaterialAttributeExample();
//            List<MaterialAttribute> oldMaterialAttributes = materialAttributeMapper.selectByExample(materialAttributeExample);
//            List<MaterialAttribute> newMaterialAttributes = JSONObject.parseArray(newJsonObject.getJSONArray("materialAttributes").toJSONString(), MaterialAttribute.class);
//            for (MaterialAttribute newEntity : newMaterialAttributes) {
//                for (MaterialAttribute oldEntity : oldMaterialAttributes) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        materialAttributeMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    materialAttributeMapper.insertSelective(newEntity);
//                }
//            }
            //商品类型
//            MaterialCategoryExample materialCategoryExample = new MaterialCategoryExample();
//            List<MaterialCategory> oldMaterialCategories = materialCategoryMapper.selectByExample(materialCategoryExample);
//            List<MaterialCategory> newMaterialCategories = JSONObject.parseArray(newJsonObject.getJSONArray("materialCategories").toJSONString(), MaterialCategory.class);
//            for (MaterialCategory newEntity : newMaterialCategories) {
//                for (MaterialCategory oldEntity : oldMaterialCategories) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        materialCategoryMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    materialCategoryMapper.insertSelective(newEntity);
//                }
//            }
            //商品当前库存
            MaterialCurrentStockExample materialCurrentStockExample = new MaterialCurrentStockExample();
            List<MaterialCurrentStock> oldMaterialCurrentStocks = materialCurrentStockMapper.selectByExample(materialCurrentStockExample);
            List<MaterialCurrentStock> newMaterialCurrentStocks = JSONObject.parseArray(newJsonObject.getJSONArray("materialCurrentStocks").toJSONString(), MaterialCurrentStock.class);
            for (MaterialCurrentStock newEntity : newMaterialCurrentStocks) {
                synchronizationTaskMapperEx.batchDeleteCurrentStockByMaterialWithDepotId(newEntity.getMaterialId()
                        ,newEntity.getDepotId());
            }
            for (MaterialCurrentStock newEntity : newMaterialCurrentStocks) {
                for (MaterialCurrentStock oldEntity : oldMaterialCurrentStocks) {
                    if (newEntity.getId().equals(oldEntity.getId())) {
                        materialCurrentStockMapper.updateByPrimaryKeySelective(newEntity);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newEntity = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newEntity != null) {
                    materialCurrentStockMapper.insertSelective(newEntity);
                }
            }
            //商品价格
//            MaterialExtendExample materialExtendExample = new MaterialExtendExample();
//            List<MaterialExtend> oldMaterialExtends = materialExtendMapper.selectByExample(materialExtendExample);
//            List<MaterialExtend> newMaterialExtends = JSONObject.parseArray(newJsonObject.getJSONArray("materialExtends").toJSONString(), MaterialExtend.class);
//            for (MaterialExtend newEntity : newMaterialExtends) {
//                for (MaterialExtend oldEntity : oldMaterialExtends) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        materialExtendMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    materialExtendMapper.insertSelective(newEntity);
//                }
//            }
            //商品初始库存
            MaterialInitialStockExample materialInitialStockExample = new MaterialInitialStockExample();
            List<MaterialInitialStock> oldMaterialInitialStocks = materialInitialStockMapper.selectByExample(materialInitialStockExample);
            List<MaterialInitialStock> newMaterialInitialStocks = JSONObject.parseArray(newJsonObject.getJSONArray("materialInitialStocks").toJSONString(), MaterialInitialStock.class);
            for (MaterialInitialStock newEntity : newMaterialInitialStocks) {
                for (MaterialInitialStock oldEntity : oldMaterialInitialStocks) {
                    if (newEntity.getId().equals(oldEntity.getId())) {
                        materialInitialStockMapper.updateByPrimaryKeySelective(newEntity);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newEntity = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newEntity != null) {
                    materialInitialStockMapper.insertSelective(newEntity);
                }
            }
//            //促销仓库
//            PromotionDepotExample promotionDepotExample = new PromotionDepotExample();
//            List<PromotionDepot> oldPromotionDepots = promotionDepotMapper.selectByExample(promotionDepotExample);
//            List<PromotionDepot> newPromotionDepots = JSONObject.parseArray(newJsonObject.getJSONArray("promotionDepots").toJSONString(), PromotionDepot.class);
//            for (PromotionDepot newEntity : newPromotionDepots) {
//                for (PromotionDepot oldEntity : oldPromotionDepots) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        promotionDepotMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    promotionDepotMapper.insertSelective(newEntity);
//                }
//            }
//            //赠品
//            PromotionGiftExample promotionGiftExample = new PromotionGiftExample();
//            List<PromotionGift> oldPromotionGifts = promotionGiftMapper.selectByExample(promotionGiftExample);
//            List<PromotionGift> newPromotionGifts = JSONObject.parseArray(newJsonObject.getJSONArray("promotionGifts").toJSONString(), PromotionGift.class);
//            for (PromotionGift newEntity : newPromotionGifts) {
//                for (PromotionGift oldEntity : oldPromotionGifts) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        promotionGiftMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    promotionGiftMapper.insertSelective(newEntity);
//                }
//            }
//            //促销主表
//            PromotionHeadExample promotionHeadExample = new PromotionHeadExample();
//            List<PromotionHead> oldPromotionHeads = promotionHeadMapper.selectByExample(promotionHeadExample);
//            List<PromotionHead> newPromotionHeads = JSONObject.parseArray(newJsonObject.getJSONArray("promotionHeads").toJSONString(), PromotionHead.class);
//            for (PromotionHead newEntity : newPromotionHeads) {
//                for (PromotionHead oldEntity : oldPromotionHeads) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        promotionHeadMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    promotionHeadMapper.insertSelective(newEntity);
//                }
//            }
//            //促销子表
//            PromotionItemExample promotionItemExample = new PromotionItemExample();
//            List<PromotionItem> oldPromotionItems = promotionItemMapper.selectByExample(promotionItemExample);
//            List<PromotionItem> newPromotionItems = JSONObject.parseArray(newJsonObject.getJSONArray("promotionItems").toJSONString(), PromotionItem.class);
//            for (PromotionItem newEntity : newPromotionItems) {
//                for (PromotionItem oldEntity : oldPromotionItems) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        promotionItemMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    promotionItemMapper.insertSelective(newEntity);
//                }
//            }
//            //促销客户
//            PromotionSupplierExample promotionSupplierExample = new PromotionSupplierExample();
//            List<PromotionSupplier> oldPromotionSuppliers = promotionSupplierMapper.selectByExample(promotionSupplierExample);
//            List<PromotionSupplier> newPromotionSuppliers = JSONObject.parseArray(newJsonObject.getJSONArray("promotionSuppliers").toJSONString(), PromotionSupplier.class);
//            for (PromotionSupplier newEntity : newPromotionSuppliers) {
//                for (PromotionSupplier oldEntity : oldPromotionSuppliers) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        promotionSupplierMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    promotionSupplierMapper.insertSelective(newEntity);
//                }
//            }
//            //商品扩展
//            MaterialPropertyExample materialPropertyExample = new MaterialPropertyExample();
//            materialPropertyExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<MaterialProperty> oldMaterialProperties = materialPropertyMapper.selectByExample(materialPropertyExample);
//            List<MaterialProperty> newMaterialProperties = JSONObject.parseArray(newJsonObject.getJSONArray("materialProperties").toJSONString(), MaterialProperty.class);
//            for (MaterialProperty newEntity : newMaterialProperties) {
//                for (MaterialProperty oldEntity : oldMaterialProperties) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        materialPropertyMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    materialPropertyMapper.insertSelective(newEntity);
//                }
//            }
            //消息
//            MsgExample msgExample = new MsgExample();
//            List<Msg> oldMsgs = msgMapper.selectByExample(msgExample);
//            List<Msg> newMsgs = JSONObject.parseArray(newJsonObject.getJSONArray("msgs").toJSONString(), Msg.class);
//            for (Msg newEntity : newMsgs) {
//                for (Msg oldEntity : oldMsgs) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        msgMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    msgMapper.insertSelective(newEntity);
//                }
//            }
//            //机构用户关系
//            OrgaUserRelExample orgaUserRelExample = new OrgaUserRelExample();
//            List<OrgaUserRel> oldOrgaUserRels = orgaUserRelMapper.selectByExample(orgaUserRelExample);
//            List<OrgaUserRel> newOrgaUserRels = JSONObject.parseArray(newJsonObject.getJSONArray("orgaUserRels").toJSONString(), OrgaUserRel.class);
//            for (OrgaUserRel newEntity : newOrgaUserRels) {
//                for (OrgaUserRel oldEntity : oldOrgaUserRels) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        orgaUserRelMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    orgaUserRelMapper.insertSelective(newEntity);
//                }
//            }
//            //机构表
//            OrganizationExample organizationExample = new OrganizationExample();
//            List<Organization> oldOrganizations = organizationMapper.selectByExample(organizationExample);
//            List<Organization> newOrganizations = JSONObject.parseArray(newJsonObject.getJSONArray("organizations").toJSONString(), Organization.class);
//            for (Organization newEntity : newOrganizations) {
//                for (Organization oldEntity : oldOrganizations) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        organizationMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    organizationMapper.insertSelective(newEntity);
//                }
//            }
//            //经手人
//            PersonExample personExample = new PersonExample();
//            List<Person> oldPersons = personMapper.selectByExample(personExample);
//            List<Person> newPersons = JSONObject.parseArray(newJsonObject.getJSONArray("persons").toJSONString(), Person.class);
//            for (Person newEntity : newPersons) {
//                for (Person oldEntity : oldPersons) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        personMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    personMapper.insertSelective(newEntity);
//                }
//            }
//            //返利表头
//            RebateExample rebateExample = new RebateExample();
//            List<Rebate> oldRebates = rebateMapper.selectByExample(rebateExample);
//            List<Rebate> newRebates = JSONObject.parseArray(newJsonObject.getJSONArray("rebates").toJSONString(), Rebate.class);
//            for (Rebate newEntity : newRebates) {
//                for (Rebate oldEntity : oldRebates) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        rebateMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    rebateMapper.insertSelective(newEntity);
//                }
//            }
//            //返利表体
//            RebateItemExample rebateItemExample = new RebateItemExample();
//            List<RebateItem> oldRebateItems = rebateItemMapper.selectByExample(rebateItemExample);
//            List<RebateItem> newRebateItems = JSONObject.parseArray(newJsonObject.getJSONArray("rebateItems").toJSONString(), RebateItem.class);
//            for (RebateItem newEntity : newRebateItems) {
//                for (RebateItem oldEntity : oldRebateItems) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        rebateItemMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    rebateItemMapper.insertSelective(newEntity);
//                }
//            }
//            //返利商品
//            RebateMaterialExample rebateMaterialExample = new RebateMaterialExample();
//            List<RebateMaterial> oldRebateMaterials = rebateMaterialMapper.selectByExample(rebateMaterialExample);
//            List<RebateMaterial> newRebateMaterials = JSONObject.parseArray(newJsonObject.getJSONArray("rebateMaterials").toJSONString(), RebateMaterial.class);
//            for (RebateMaterial newEntity : newRebateMaterials) {
//                for (RebateMaterial oldEntity : oldRebateMaterials) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        rebateMaterialMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    rebateMaterialMapper.insertSelective(newEntity);
//                }
//            }
//            //返利规则
//            RebateRuleExample rebateRuleExample = new RebateRuleExample();
//            List<RebateRule> oldRebateRules = rebateRuleMapper.selectByExample(rebateRuleExample);
//            List<RebateRule> newRebateRules = JSONObject.parseArray(newJsonObject.getJSONArray("rebateRules").toJSONString(), RebateRule.class);
//            for (RebateRule newEntity : newRebateRules) {
//                for (RebateRule oldEntity : oldRebateRules) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        rebateRuleMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    rebateRuleMapper.insertSelective(newEntity);
//                }
//            }
            //角色
            RoleExample roleExample = new RoleExample();
            List<Role> oldRoles = roleMapper.selectByExample(roleExample);
            List<Role> newRoles = JSONObject.parseArray(newJsonObject.getJSONArray("roles").toJSONString(), Role.class);
            for (Role newEntity : newRoles) {
                for (Role oldEntity : oldRoles) {
                    if (newEntity.getId().equals(oldEntity.getId())) {
                        roleMapper.updateByPrimaryKeySelective(newEntity);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newEntity = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newEntity != null) {
                    roleMapper.insertSelective(newEntity);
                }
            }
            //序列号
            SerialNumberExample serialNumberExample = new SerialNumberExample();
            List<SerialNumber> oldSerialNumbers = serialNumberMapper.selectByExample(serialNumberExample);
            List<SerialNumber> newSerialNumbers = JSONObject.parseArray(newJsonObject.getJSONArray("serialNumbers").toJSONString(), SerialNumber.class);
            for (SerialNumber newEntity : newSerialNumbers) {
                for (SerialNumber oldEntity : oldSerialNumbers) {
                    if (newEntity.getId().equals(oldEntity.getId())) {
                        serialNumberMapper.updateByPrimaryKeySelective(newEntity);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newEntity = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newEntity != null) {
                    serialNumberMapper.insertSelective(newEntity);
                }
            }
//            //供应商/客户
//            SupplierExample supplierExample = new SupplierExample();
//            List<Supplier> oldSuppliers = supplierMapper.selectByExample(supplierExample);
//            List<Supplier> newSuppliers = JSONObject.parseArray(newJsonObject.getJSONArray("suppliers").toJSONString(), Supplier.class);
//            for (Supplier newEntity : newSuppliers) {
//                for (Supplier oldEntity : oldSuppliers) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        supplierMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    supplierMapper.insertSelective(newEntity);
//                }
//            }
            //系统参数
            SystemConfigExample systemConfigExample = new SystemConfigExample();
            List<SystemConfig> oldSystemConfigs = systemConfigMapper.selectByExample(systemConfigExample);
            List<SystemConfig> newSystemConfigs = JSONObject.parseArray(newJsonObject.getJSONArray("systemConfigs").toJSONString(), SystemConfig.class);
            for (SystemConfig newEntity : newSystemConfigs) {
                for (SystemConfig oldEntity : oldSystemConfigs) {
                    if (newEntity.getId().equals(oldEntity.getId())) {
                        systemConfigMapper.updateByPrimaryKeySelective(newEntity);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newEntity = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newEntity != null) {
                    systemConfigMapper.insertSelective(newEntity);
                }
            }
            //租户
            List<Tenant> oldTenants = tenantMapper.selectByExample(new TenantExample());
            newJsonObject.get("tenants");
            List<Tenant> newTenants = JSONObject.parseArray(newJsonObject.getJSONArray("tenants").toJSONString(), Tenant.class);
            for (Tenant newEntity : newTenants) {
                for (Tenant oldEntity : oldTenants) {
                    if (newEntity.getId().equals(oldEntity.getId())) {
                        tenantMapper.updateByPrimaryKeySelective(newEntity);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newEntity = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newEntity != null) {
                    tenantMapper.insertSelective(newEntity);
                }
            }
            //单位
//            UnitExample unitExample = new UnitExample();
//            List<Unit> oldUnits = unitMapper.selectByExample(unitExample);
//            List<Unit> newUnits = JSONObject.parseArray(newJsonObject.getJSONArray("units").toJSONString(), Unit.class);
//            for (Unit newEntity : newUnits) {
//                for (Unit oldEntity : oldUnits) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        unitMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    unitMapper.insertSelective(newEntity);
//                }
//            }
            //用户
            List<User> oldUsers = userMapper.selectByExample(new UserExample());
            newJsonObject.get("users");
            List<User> newUsers = JSONObject.parseArray(newJsonObject.getJSONArray("users").toJSONString(), User.class);
            for (User newEntity : newUsers) {
                for (User oldEntity : oldUsers) {
                    if (newEntity.getId().equals(oldEntity.getId())) {
                        userMapper.updateByPrimaryKeySelective(newEntity);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newEntity = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newEntity != null) {
                    userMapper.insertSelective(newEntity);
                }
            }
            //用户-角色-模块关系
            UserBusinessExample userBusinessExample = new UserBusinessExample();
            List<UserBusiness> oldUserBusinesses = userBusinessMapper.selectByExample(userBusinessExample);
            List<UserBusiness> newUserBusinesses = JSONObject.parseArray(newJsonObject.getJSONArray("userBusinesses").toJSONString(), UserBusiness.class);
            for (UserBusiness newEntity : newUserBusinesses) {
                for (UserBusiness oldEntity : oldUserBusinesses) {
                    if (newEntity.getId().equals(oldEntity.getId())) {
                        userBusinessMapper.updateByPrimaryKeySelective(newEntity);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newEntity = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newEntity != null) {
                    userBusinessMapper.insertSelective(newEntity);
                }
            }
//            //用户类型
//            UserCategoryExample userCategoryExample = new UserCategoryExample();
//            List<UserCategory> oldUserCategories = userCategoryMapper.selectByExample(userCategoryExample);
//            List<UserCategory> newUserCategories = JSONObject.parseArray(newJsonObject.getJSONArray("userCategories").toJSONString(), UserCategory.class);
//            for (UserCategory newEntity : newUserCategories) {
//                for (UserCategory oldEntity : oldUserCategories) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        userCategoryMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    userCategoryMapper.insertSelective(newEntity);
//                }
//            }
            //审批明细
            WorkflowApproveDetailExample workflowApproveDetailExample = new WorkflowApproveDetailExample();
            List<WorkflowApproveDetail> oldWorkflowApproveDetails = workflowApproveDetailMapper.selectByExample(workflowApproveDetailExample);
            List<WorkflowApproveDetail> newWorkflowApproveDetails = JSONObject.parseArray(newJsonObject.getJSONArray("workflowApproveDetails").toJSONString(), WorkflowApproveDetail.class);
            for (WorkflowApproveDetail newEntity : newWorkflowApproveDetails) {
                for (WorkflowApproveDetail oldEntity : oldWorkflowApproveDetails) {
                    if (newEntity.getId().equals(oldEntity.getId())) {
                        workflowApproveDetailMapper.updateByPrimaryKeySelective(newEntity);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newEntity = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newEntity != null) {
                    workflowApproveDetailMapper.insertSelective(newEntity);
                }
            }
            //配置明细
            WorkflowConfigDetailExample workflowConfigDetailExample = new WorkflowConfigDetailExample();
            List<WorkflowConfigDetail> oldWorkflowConfigDetails = workflowConfigDetailMapper.selectByExample(workflowConfigDetailExample);
            List<WorkflowConfigDetail> newWorkflowConfigDetails = JSONObject.parseArray(newJsonObject.getJSONArray("workflowConfigDetails").toJSONString(), WorkflowConfigDetail.class);
            for (WorkflowConfigDetail newEntity : newWorkflowConfigDetails) {
                for (WorkflowConfigDetail oldEntity : oldWorkflowConfigDetails) {
                    if (newEntity.getId().equals(oldEntity.getId())) {
                        workflowConfigDetailMapper.updateByPrimaryKeySelective(newEntity);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newEntity = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newEntity != null) {
                    workflowConfigDetailMapper.insertSelective(newEntity);
                }
            }
            //配置主表
            WorkflowConfigMainExample workflowConfigMainExample = new WorkflowConfigMainExample();
            List<WorkflowConfigMain> oldWorkflowConfigMains = workflowConfigMainMapper.selectByExample(workflowConfigMainExample);
            List<WorkflowConfigMain> newWorkflowConfigMains = JSONObject.parseArray(newJsonObject.getJSONArray("workflowConfigMains").toJSONString(), WorkflowConfigMain.class);
            for (WorkflowConfigMain newEntity : newWorkflowConfigMains) {
                for (WorkflowConfigMain oldEntity : oldWorkflowConfigMains) {
                    if (newEntity.getId().equals(oldEntity.getId())) {
                        workflowConfigMainMapper.updateByPrimaryKeySelective(newEntity);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newEntity = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newEntity != null) {
                    workflowConfigMainMapper.insertSelective(newEntity);
                }
            }
            //处理详情
            WorkflowProcessDetailExample workflowProcessDetailExample = new WorkflowProcessDetailExample();
            List<WorkflowProcessDetail> oldProcessDetails = workflowProcessDetailMapper.selectByExample(workflowProcessDetailExample);
            List<WorkflowProcessDetail> newProcessDetails = JSONObject.parseArray(newJsonObject.getJSONArray("processDetails").toJSONString(), WorkflowProcessDetail.class);
            for (WorkflowProcessDetail newEntity : newProcessDetails) {
                for (WorkflowProcessDetail oldEntity : oldProcessDetails) {
                    if (newEntity.getId().equals(oldEntity.getId())) {
                        workflowProcessDetailMapper.updateByPrimaryKeySelective(newEntity);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newEntity = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newEntity != null) {
                    workflowProcessDetailMapper.insertSelective(newEntity);
                }
            }
            //处理详情历史记录
            WorkflowProcessDetailHisExample workflowProcessDetailHisExample = new WorkflowProcessDetailHisExample();
            List<WorkflowProcessDetailHis> oldProcessDetailHis = workflowProcessDetailHisMapper.selectByExample(workflowProcessDetailHisExample);
            List<WorkflowProcessDetailHis> newProcessDetailHis = JSONObject.parseArray(newJsonObject.getJSONArray("processDetailHis").toJSONString(), WorkflowProcessDetailHis.class);
            for (WorkflowProcessDetailHis newEntity : newProcessDetailHis) {
                for (WorkflowProcessDetailHis oldEntity : oldProcessDetailHis) {
                    if (newEntity.getId().equals(oldEntity.getId())) {
                        workflowProcessDetailHisMapper.updateByPrimaryKeySelective(newEntity);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newEntity = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newEntity != null) {
                    workflowProcessDetailHisMapper.insertSelective(newEntity);
                }
            }
            //钱箱金额修改记录
//            CashBoxRecordExample cashBoxRecordExample = new CashBoxRecordExample();
//            List<CashBoxRecord> oldCashBoxRecords = cashBoxRecordMapper.selectByExample(cashBoxRecordExample);
//            List<CashBoxRecord> newCashBoxRecords = JSONObject.parseArray(newJsonObject.getJSONArray("cashBoxRecords").toJSONString(), CashBoxRecord.class);
//            for (CashBoxRecord newEntity : newCashBoxRecords) {
//                for (CashBoxRecord oldEntity : oldCashBoxRecords) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        cashBoxRecordMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    cashBoxRecordMapper.insertSelective(newEntity);
//                }
//            }
            //收银员上班记录
//            RetailRecordExample retailRecordExample = new RetailRecordExample();
//            List<RetailRecord> oldRetailRecords = retailRecordMapper.selectByExample(retailRecordExample);
//            List<RetailRecord> newRetailRecords = JSONObject.parseArray(newJsonObject.getJSONArray("retailRecords").toJSONString(), RetailRecord.class);
//            for (RetailRecord newEntity : newRetailRecords) {
//                for (RetailRecord oldEntity : oldRetailRecords) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        retailRecordMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    retailRecordMapper.insertSelective(newEntity);
//                }
//            }
            //地址信息
//            AddressExample addressExample = new AddressExample();
//            List<Address> oldAddress = addressMapper.selectByExample(addressExample);
//            List<Address> newAddress = JSONObject.parseArray(newJsonObject.getJSONArray("addresses").toJSONString(), Address.class);
//            for (Address newEntity : newAddress) {
//                for (Address oldEntity : oldAddress) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        addressMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    addressMapper.insertSelective(newEntity);
//                }
//            }
//            //运输公司
//            TransportExample transportExample = new TransportExample();
//            List<Transport> oldTransport = transportMapper.selectByExample(transportExample);
//            List<Transport> newTransport = JSONObject.parseArray(newJsonObject.getJSONArray("transports").toJSONString(), Transport.class);
//            for (Transport newEntity : newTransport) {
//                for (Transport oldEntity : oldTransport) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        transportMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    transportMapper.insertSelective(newEntity);
//                }
//            }
        } catch (Exception e) {
            JshException.writeFail(logger, e, this.getLanCode());
        }
    }

    /**
     * @Author: wy
     * @Description: 查询总店关于分店的数据
     * @DateTime: 2022-08-23 17:26
     * @Params:
     * @Return
     */
    public JSONObject getMaterialNewJsonObject(String tenantId) {
        JSONObject oldJsonObject = new JSONObject();
        //财务单据表头
        AccountHeadExample accountHeadExample = new AccountHeadExample();
        accountHeadExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<AccountHead> accountHeads = accountHeadMapper.selectByExample(accountHeadExample);
        oldJsonObject.put("accountHeads", accountHeads);
        //财务单据表体
        AccountItemExample accountItemExample = new AccountItemExample();
        accountItemExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<AccountItem> accountItems = accountItemMapper.selectByExample(accountItemExample);
        oldJsonObject.put("accountItems", accountItems);
        //账户信息
        AccountExample accountExample = new AccountExample();
        accountExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<Account> accounts = accountMapper.selectByExample(accountExample);
        oldJsonObject.put("accounts", accounts);
        //附件
        AttachmentExample attachmentExample = new AttachmentExample();
        attachmentExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<Attachment> attachments = attachmentMapper.selectByExample(attachmentExample);
        oldJsonObject.put("attachments", attachments);
        //仓库
        DepotExample depotExample = new DepotExample();
        depotExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<Depot> depots = depotMapper.selectByExample(depotExample);
        oldJsonObject.put("depots", depots);
        //单据表头
        DepotHeadExample depotHeadExample = new DepotHeadExample();
        depotHeadExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<DepotHead> depotHeads = depotHeadMapper.selectByExample(depotHeadExample);
        oldJsonObject.put("depotHeads", depotHeads);
        //单据表体
        DepotItemExample depotItemExample = new DepotItemExample();
        depotItemExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<DepotItem> depotItems = depotItemMapper.selectByExample(depotItemExample);
        oldJsonObject.put("depotItems", depotItems);
        //收支项目
        InOutItemExample inOutItemExample = new InOutItemExample();
        inOutItemExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<InOutItem> inOutItems = inOutItemMapper.selectByExample(inOutItemExample);
        oldJsonObject.put("inOutItems", inOutItems);
        //商品
        MaterialExample materialExample = new MaterialExample();
        materialExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<Material> materials = materialMapper.selectByExample(materialExample);
        oldJsonObject.put("materials", materials);
        //商品属性
        MaterialAttributeExample materialAttributeExample = new MaterialAttributeExample();
        materialAttributeExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<MaterialAttribute> materialAttributes = materialAttributeMapper.selectByExample(materialAttributeExample);
        oldJsonObject.put("materialAttributes", materialAttributes);
        //商品类型
        MaterialCategoryExample materialCategoryExample = new MaterialCategoryExample();
        materialCategoryExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<MaterialCategory> materialCategories = materialCategoryMapper.selectByExample(materialCategoryExample);
        oldJsonObject.put("materialCategories", materialCategories);
        //商品当前库存
        MaterialCurrentStockExample materialCurrentStockExample = new MaterialCurrentStockExample();
        materialCurrentStockExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<MaterialCurrentStock> materialCurrentStocks = materialCurrentStockMapper.selectByExample(materialCurrentStockExample);
        oldJsonObject.put("materialCurrentStocks", materialCurrentStocks);
        //商品价格
        MaterialExtendExample materialExtendExample = new MaterialExtendExample();
        materialExtendExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<MaterialExtend> materialExtends = materialExtendMapper.selectByExample(materialExtendExample);
        oldJsonObject.put("materialExtends", materialExtends);
        //商品初始库存
        MaterialInitialStockExample materialInitialStockExample = new MaterialInitialStockExample();
        materialInitialStockExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<MaterialInitialStock> materialInitialStocks = materialInitialStockMapper.selectByExample(materialInitialStockExample);
        oldJsonObject.put("materialInitialStocks", materialInitialStocks);
        //促销仓库
        PromotionDepotExample promotionDepotExample = new PromotionDepotExample();
        promotionDepotExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<PromotionDepot> promotionDepots = promotionDepotMapper.selectByExample(promotionDepotExample);
        oldJsonObject.put("promotionDepots", promotionDepots);
        //赠品
        PromotionGiftExample promotionGiftExample = new PromotionGiftExample();
        promotionGiftExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<PromotionGift> promotionGifts = promotionGiftMapper.selectByExample(promotionGiftExample);
        oldJsonObject.put("promotionGifts", promotionGifts);
        //促销主表
        PromotionHeadExample promotionHeadExample = new PromotionHeadExample();
        promotionHeadExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<PromotionHead> promotionHeads = promotionHeadMapper.selectByExample(promotionHeadExample);
        oldJsonObject.put("promotionHeads", promotionHeads);
        //促销子表
        PromotionItemExample promotionItemExample = new PromotionItemExample();
        promotionItemExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<PromotionItem> promotionItems = promotionItemMapper.selectByExample(promotionItemExample);
        oldJsonObject.put("promotionItems", promotionItems);
        //促销客户
        PromotionSupplierExample promotionSupplierExample = new PromotionSupplierExample();
        promotionSupplierExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<PromotionSupplier> promotionSuppliers = promotionSupplierMapper.selectByExample(promotionSupplierExample);
        oldJsonObject.put("promotionSuppliers", promotionSuppliers);
//        //商品扩展
//        MaterialPropertyExample materialPropertyExample = new MaterialPropertyExample();
//        materialPropertyExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//        List<MaterialProperty> materialProperties = materialPropertyMapper.selectByExample(materialPropertyExample);
//        oldJsonObject.put("materialProperties", materialProperties);
        //消息
        MsgExample msgExample = new MsgExample();
        msgExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<Msg> msgs = msgMapper.selectByExample(msgExample);
        oldJsonObject.put("msgs", msgs);
        //机构用户关系
        OrgaUserRelExample orgaUserRelExample = new OrgaUserRelExample();
        orgaUserRelExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<OrgaUserRel> orgaUserRels = orgaUserRelMapper.selectByExample(orgaUserRelExample);
        oldJsonObject.put("orgaUserRels", orgaUserRels);
        //机构表
        OrganizationExample organizationExample = new OrganizationExample();
        organizationExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<Organization> organizations = organizationMapper.selectByExample(organizationExample);
        oldJsonObject.put("organizations", organizations);
        //经手人
        PersonExample personExample = new PersonExample();
        personExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<Person> persons = personMapper.selectByExample(personExample);
        oldJsonObject.put("persons", persons);
        //返利表头
        RebateExample rebateExample = new RebateExample();
        rebateExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<Rebate> rebates = rebateMapper.selectByExample(rebateExample);
        oldJsonObject.put("rebates", rebates);
        //返利表体
        RebateItemExample rebateItemExample = new RebateItemExample();
//        rebateItemExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        rebateItemExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
        List<RebateItem> rebateItems = rebateItemMapper.selectByExample(rebateItemExample);
        oldJsonObject.put("rebateItems", rebateItems);
        //返利商品
        RebateMaterialExample rebateMaterialExample = new RebateMaterialExample();
//        rebateMaterialExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        rebateMaterialExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
        List<RebateMaterial> rebateMaterials = rebateMaterialMapper.selectByExample(rebateMaterialExample);
        oldJsonObject.put("rebateMaterials", rebateMaterials);
        //返利规则
        RebateRuleExample rebateRuleExample = new RebateRuleExample();
//        rebateRuleExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        rebateRuleExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
        List<RebateRule> rebateRules = rebateRuleMapper.selectByExample(rebateRuleExample);
        oldJsonObject.put("rebateRules", rebateRules);
        //角色
        RoleExample roleExample = new RoleExample();
        roleExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<Role> roles = roleMapper.selectByExample(roleExample);
        oldJsonObject.put("roles", roles);
        //序列号
        SerialNumberExample serialNumberExample = new SerialNumberExample();
        serialNumberExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<SerialNumber> serialNumbers = serialNumberMapper.selectByExample(serialNumberExample);
        oldJsonObject.put("serialNumbers", serialNumbers);
        //供应商/客户
        SupplierExample supplierExample = new SupplierExample();
        supplierExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<Supplier> suppliers = supplierMapper.selectByExample(supplierExample);
        oldJsonObject.put("suppliers", suppliers);
        //系统参数
        SystemConfigExample systemConfigExample = new SystemConfigExample();
        systemConfigExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<SystemConfig> systemConfigs = systemConfigMapper.selectByExample(systemConfigExample);
        oldJsonObject.put("systemConfigs", systemConfigs);
        //租户
//        TenantExample tenantExample = new TenantExample();
//        tenantExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<Tenant> tenants = tenantMapper.selectByExample(new TenantExample());
        oldJsonObject.put("tenants", tenants);
        //单位
        UnitExample unitExample = new UnitExample();
        unitExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<Unit> units = unitMapper.selectByExample(unitExample);
        oldJsonObject.put("units", units);
        //用户
//        UserExample userExample = new UserExample();
//        userExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<User> users = userMapper.selectByExample(new UserExample());
        oldJsonObject.put("users", users);
        //用户-角色-模块关系
        UserBusinessExample userBusinessExample = new UserBusinessExample();
        userBusinessExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<UserBusiness> userBusinesses = userBusinessMapper.selectByExample(userBusinessExample);
        oldJsonObject.put("userBusinesses", userBusinesses);
        //用户类型
        UserCategoryExample userCategoryExample = new UserCategoryExample();
        userCategoryExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<UserCategory> userCategories = userCategoryMapper.selectByExample(userCategoryExample);
        oldJsonObject.put("userCategories", userCategories);
        //审批明细
        WorkflowApproveDetailExample workflowApproveDetailExample = new WorkflowApproveDetailExample();
        workflowApproveDetailExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<WorkflowApproveDetail> workflowApproveDetails = workflowApproveDetailMapper.selectByExample(workflowApproveDetailExample);
        oldJsonObject.put("workflowApproveDetails", workflowApproveDetails);
        //配置明细
        WorkflowConfigDetailExample workflowConfigDetailExample = new WorkflowConfigDetailExample();
        workflowConfigDetailExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<WorkflowConfigDetail> workflowConfigDetails = workflowConfigDetailMapper.selectByExample(workflowConfigDetailExample);
        oldJsonObject.put("workflowConfigDetails", workflowConfigDetails);
        //配置主表
        WorkflowConfigMainExample workflowConfigMainExample = new WorkflowConfigMainExample();
        workflowConfigMainExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<WorkflowConfigMain> workflowConfigMains = workflowConfigMainMapper.selectByExample(workflowConfigMainExample);
        oldJsonObject.put("workflowConfigMains", workflowConfigMains);
        //处理详情
        WorkflowProcessDetailExample workflowProcessDetailExample = new WorkflowProcessDetailExample();
        workflowProcessDetailExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<WorkflowProcessDetail> processDetails = workflowProcessDetailMapper.selectByExample(workflowProcessDetailExample);
        oldJsonObject.put("processDetails", processDetails);
        //处理详情历史记录
        WorkflowProcessDetailHisExample workflowProcessDetailHisExample = new WorkflowProcessDetailHisExample();
        workflowProcessDetailHisExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andTenantIdEqualTo(tenantId);
        List<WorkflowProcessDetailHis> processDetailHis = workflowProcessDetailHisMapper.selectByExample(workflowProcessDetailHisExample);
        oldJsonObject.put("processDetailHis", processDetailHis);
        return oldJsonObject;
    }

    /**
     * @Author: wy
     * @Description: 下载总店关于分店的数据
     * @DateTime: 2022-08-23 17:26
     * @Params:
     * @Return
     */
    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    public void synchronizationStore(JSONObject newJsonObject, String tenantId) {
        try {
            //财务单据表头
            AccountHeadExample accountHeadExample = new AccountHeadExample();
            accountHeadExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
            List<AccountHead> oldAccountHeads = accountHeadMapper.selectByExample(accountHeadExample);
            List<AccountHead> newAccountHeads = JSONObject.parseArray(newJsonObject.getJSONArray("accountHeads").toJSONString(), AccountHead.class);
            for (AccountHead newAccountHead : newAccountHeads) {
                newAccountHead.setTenantId(tenantId);
                for (AccountHead oldAccountHead : oldAccountHeads) {
                    if (newAccountHead.getId().equals(oldAccountHead.getId())) {
                        accountHeadMapper.updateByPrimaryKeySelective(newAccountHead);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newAccountHead = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newAccountHead != null) {
                    accountHeadMapper.insertSelective(newAccountHead);
                }
            }

            //财务单据表体
            AccountItemExample accountItemExample = new AccountItemExample();
            accountItemExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
            List<AccountItem> oldAccountItems = accountItemMapper.selectByExample(accountItemExample);
            List<AccountItem> newAccountItems = JSONObject.parseArray(newJsonObject.getJSONArray("accountItems").toJSONString(), AccountItem.class);
            for (AccountItem newAccountItem : newAccountItems) {
                newAccountItem.setTenantId(tenantId);
                for (AccountItem oldAccountItem : oldAccountItems) {
                    if (newAccountItem.getId().equals(oldAccountItem.getId())) {
                        accountItemMapper.updateByPrimaryKeySelective(newAccountItem);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newAccountItem = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newAccountItem != null) {
                    accountItemMapper.insertSelective(newAccountItem);
                }
            }
            //账户信息
            AccountExample accountExample = new AccountExample();
            accountExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
            List<Account> oldAccounts = accountMapper.selectByExample(accountExample);
            List<Account> newAccounts = JSONObject.parseArray(newJsonObject.getJSONArray("accounts").toJSONString(), Account.class);
            for (Account newAccount : newAccounts) {
                newAccount.setTenantId(tenantId);
                for (Account oldAccount : oldAccounts) {
                    if (newAccount.getId().equals(oldAccount.getId())) {
                        accountMapper.updateByPrimaryKeySelective(newAccount);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newAccount = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newAccount != null) {
                    accountMapper.insertSelective(newAccount);
                }
            }
            //附件
            AttachmentExample attachmentExample = new AttachmentExample();
            attachmentExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
            List<Attachment> oldAttachments = attachmentMapper.selectByExample(attachmentExample);
            List<Attachment> newAttachments = JSONObject.parseArray(newJsonObject.getJSONArray("attachments").toJSONString(), Attachment.class);
            for (Attachment newAttachment : newAttachments) {
                newAttachment.setTenantId(tenantId);
                for (Attachment oldAttachment : oldAttachments) {
                    if (newAttachment.getId().equals(oldAttachment.getId())) {
                        attachmentMapper.updateByPrimaryKeySelective(newAttachment);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newAttachment = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newAttachment != null) {
                    attachmentMapper.insertSelective(newAttachment);
                }
            }
            //仓库
            DepotExample depotExample = new DepotExample();
            depotExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
            List<Depot> oldDepots = depotMapper.selectByExample(depotExample);
            List<Depot> newDepots = JSONObject.parseArray(newJsonObject.getJSONArray("depots").toJSONString(), Depot.class);
            for (Depot newDepot : newDepots) {
                newDepot.setTenantId(tenantId);
                for (Depot oldDepot : oldDepots) {
                    if (newDepot.getId().equals(oldDepot.getId())) {
                        depotMapper.updateByPrimaryKeySelective(newDepot);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newDepot = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newDepot != null) {
                    depotMapper.insertSelective(newDepot);
                }
            }
            //单据表头
            DepotHeadExample depotHeadExample = new DepotHeadExample();
            depotHeadExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
            List<DepotHead> oldDepotHeads = depotHeadMapper.selectByExample(depotHeadExample);
            List<DepotHead> newDepotHeads = JSONObject.parseArray(newJsonObject.getJSONArray("depotHeads").toJSONString(), DepotHead.class);
            for (DepotHead newEntity : newDepotHeads) {
                //                newEntity.setTenantId(tenantId);
                newEntity.setTenantId(null);
                for (DepotHead oldEntity : oldDepotHeads) {
                    if (newEntity.getId().equals(oldEntity.getId())) {
                        depotHeadMapper.updateByPrimaryKeySelective(newEntity);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newEntity = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newEntity != null) {
                    depotHeadMapper.insertSelective(newEntity);
                }
            }
            //单据表体
            DepotItemExample depotItemExample = new DepotItemExample();
            depotItemExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
            List<DepotItem> oldDepotItems = depotItemMapper.selectByExample(depotItemExample);
            List<DepotItem> newDepotItems = JSONObject.parseArray(newJsonObject.getJSONArray("depotItems").toJSONString(), DepotItem.class);
            for (DepotItem newEntity : newDepotItems) {
                //                newEntity.setTenantId(tenantId);
                newEntity.setTenantId(null);
                for (DepotItem oldEntity : oldDepotItems) {
                    if (newEntity.getId().equals(oldEntity.getId())) {
                        depotItemMapper.updateByPrimaryKeySelective(newEntity);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newEntity = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newEntity != null) {
                    depotItemMapper.insertSelective(newEntity);
                }
            }
            //收支项目
            InOutItemExample inOutItemExample = new InOutItemExample();
            inOutItemExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
            List<InOutItem> oldInOutItems = inOutItemMapper.selectByExample(inOutItemExample);
            List<InOutItem> newInOutItems = JSONObject.parseArray(newJsonObject.getJSONArray("inOutItems").toJSONString(), InOutItem.class);
            for (InOutItem newEntity : newInOutItems) {
                //                newEntity.setTenantId(tenantId);
                newEntity.setTenantId(null);
                for (InOutItem oldEntity : oldInOutItems) {
                    if (newEntity.getId().equals(oldEntity.getId())) {
                        inOutItemMapper.updateByPrimaryKeySelective(newEntity);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newEntity = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newEntity != null) {
                    inOutItemMapper.insertSelective(newEntity);
                }
            }
            //商品
            MaterialExample materialExample = new MaterialExample();
            materialExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
            List<Material> oldMaterials = materialMapper.selectByExample(materialExample);
            List<Material> newMaterials = JSONObject.parseArray(newJsonObject.getJSONArray("materials").toJSONString(), Material.class);
            for (Material newEntity : newMaterials) {
                //                newEntity.setTenantId(tenantId);
                newEntity.setTenantId(null);
                for (Material oldEntity : oldMaterials) {
                    if (newEntity.getId().equals(oldEntity.getId())) {
                        materialMapper.updateByPrimaryKeySelective(newEntity);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newEntity = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newEntity != null) {
                    materialMapper.insertSelective(newEntity);
                }
            }
            //商品属性
            MaterialAttributeExample materialAttributeExample = new MaterialAttributeExample();
            materialAttributeExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
            List<MaterialAttribute> oldMaterialAttributes = materialAttributeMapper.selectByExample(materialAttributeExample);
            List<MaterialAttribute> newMaterialAttributes = JSONObject.parseArray(newJsonObject.getJSONArray("materialAttributes").toJSONString(), MaterialAttribute.class);
            for (MaterialAttribute newEntity : newMaterialAttributes) {
                //                newEntity.setTenantId(tenantId);
                newEntity.setTenantId(null);
                for (MaterialAttribute oldEntity : oldMaterialAttributes) {
                    if (newEntity.getId().equals(oldEntity.getId())) {
                        materialAttributeMapper.updateByPrimaryKeySelective(newEntity);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newEntity = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newEntity != null) {
                    materialAttributeMapper.insertSelective(newEntity);
                }
            }
//            //商品类型
//            MaterialCategoryExample materialCategoryExample = new MaterialCategoryExample();
//            materialCategoryExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<MaterialCategory> oldMaterialCategories = materialCategoryMapper.selectByExample(materialCategoryExample);
//            List<MaterialCategory> newMaterialCategories = JSONObject.parseArray(newJsonObject.getJSONArray("materialCategories").toJSONString(), MaterialCategory.class);
//            for (MaterialCategory newEntity : newMaterialCategories) {
//                //                newEntity.setTenantId(tenantId);
//                newEntity.setTenantId(null);
//                for (MaterialCategory oldEntity : oldMaterialCategories) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        materialCategoryMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    materialCategoryMapper.insertSelective(newEntity);
//                }
//            }
//            //商品当前库存
//            MaterialCurrentStockExample materialCurrentStockExample = new MaterialCurrentStockExample();
//            materialCurrentStockExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<MaterialCurrentStock> oldMaterialCurrentStocks = materialCurrentStockMapper.selectByExample(materialCurrentStockExample);
//            List<MaterialCurrentStock> newMaterialCurrentStocks = JSONObject.parseArray(newJsonObject.getJSONArray("materialCurrentStocks").toJSONString(), MaterialCurrentStock.class);
//            for (MaterialCurrentStock newEntity : newMaterialCurrentStocks) {
//                //                newEntity.setTenantId(tenantId);
//                newEntity.setTenantId(null);
//                for (MaterialCurrentStock oldEntity : oldMaterialCurrentStocks) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        materialCurrentStockMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    materialCurrentStockMapper.insertSelective(newEntity);
//                }
//            }
//            //商品价格
//            MaterialExtendExample materialExtendExample = new MaterialExtendExample();
//            materialExtendExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<MaterialExtend> oldMaterialExtends = materialExtendMapper.selectByExample(materialExtendExample);
//            List<MaterialExtend> newMaterialExtends = JSONObject.parseArray(newJsonObject.getJSONArray("materialExtends").toJSONString(), MaterialExtend.class);
//            for (MaterialExtend newEntity : newMaterialExtends) {
//                //                newEntity.setTenantId(tenantId);
//                newEntity.setTenantId(null);
//                for (MaterialExtend oldEntity : oldMaterialExtends) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        materialExtendMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    materialExtendMapper.insertSelective(newEntity);
//                }
//            }
//            //商品初始库存
//            MaterialInitialStockExample materialInitialStockExample = new MaterialInitialStockExample();
//            materialInitialStockExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<MaterialInitialStock> oldMaterialInitialStocks = materialInitialStockMapper.selectByExample(materialInitialStockExample);
//            List<MaterialInitialStock> newMaterialInitialStocks = JSONObject.parseArray(newJsonObject.getJSONArray("materialInitialStocks").toJSONString(), MaterialInitialStock.class);
//            for (MaterialInitialStock newEntity : newMaterialInitialStocks) {
//                //                newEntity.setTenantId(tenantId);
//                newEntity.setTenantId(null);
//                for (MaterialInitialStock oldEntity : oldMaterialInitialStocks) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        materialInitialStockMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    materialInitialStockMapper.insertSelective(newEntity);
//                }
//            }
//            //促销仓库
//            PromotionDepotExample promotionDepotExample = new PromotionDepotExample();
//            promotionDepotExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<PromotionDepot> oldPromotionDepots = promotionDepotMapper.selectByExample(promotionDepotExample);
//            List<PromotionDepot> newPromotionDepots = JSONObject.parseArray(newJsonObject.getJSONArray("promotionDepots").toJSONString(), PromotionDepot.class);
//            for (PromotionDepot newEntity : newPromotionDepots) {
//                //                newEntity.setTenantId(tenantId);
//                newEntity.setTenantId(null);
//                for (PromotionDepot oldEntity : oldPromotionDepots) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        promotionDepotMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    promotionDepotMapper.insertSelective(newEntity);
//                }
//            }
//            //赠品
//            PromotionGiftExample promotionGiftExample = new PromotionGiftExample();
//            promotionGiftExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<PromotionGift> oldPromotionGifts = promotionGiftMapper.selectByExample(promotionGiftExample);
//            List<PromotionGift> newPromotionGifts = JSONObject.parseArray(newJsonObject.getJSONArray("promotionGifts").toJSONString(), PromotionGift.class);
//            for (PromotionGift newEntity : newPromotionGifts) {
//                //                newEntity.setTenantId(tenantId);
//                newEntity.setTenantId(null);
//                for (PromotionGift oldEntity : oldPromotionGifts) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        promotionGiftMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    promotionGiftMapper.insertSelective(newEntity);
//                }
//            }
//            //促销主表
//            PromotionHeadExample promotionHeadExample = new PromotionHeadExample();
//            promotionHeadExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<PromotionHead> oldPromotionHeads = promotionHeadMapper.selectByExample(promotionHeadExample);
//            List<PromotionHead> newPromotionHeads = JSONObject.parseArray(newJsonObject.getJSONArray("promotionHeads").toJSONString(), PromotionHead.class);
//            for (PromotionHead newEntity : newPromotionHeads) {
//                //                newEntity.setTenantId(tenantId);
//                newEntity.setTenantId(null);
//                for (PromotionHead oldEntity : oldPromotionHeads) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        promotionHeadMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    promotionHeadMapper.insertSelective(newEntity);
//                }
//            }
//            //促销子表
//            PromotionItemExample promotionItemExample = new PromotionItemExample();
//            promotionItemExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<PromotionItem> oldPromotionItems = promotionItemMapper.selectByExample(promotionItemExample);
//            List<PromotionItem> newPromotionItems = JSONObject.parseArray(newJsonObject.getJSONArray("promotionItems").toJSONString(), PromotionItem.class);
//            for (PromotionItem newEntity : newPromotionItems) {
//                //                newEntity.setTenantId(tenantId);
//                newEntity.setTenantId(null);
//                for (PromotionItem oldEntity : oldPromotionItems) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        promotionItemMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    promotionItemMapper.insertSelective(newEntity);
//                }
//            }
//            //促销客户
//            PromotionSupplierExample promotionSupplierExample = new PromotionSupplierExample();
//            promotionSupplierExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<PromotionSupplier> oldPromotionSuppliers = promotionSupplierMapper.selectByExample(promotionSupplierExample);
//            List<PromotionSupplier> newPromotionSuppliers = JSONObject.parseArray(newJsonObject.getJSONArray("promotionSuppliers").toJSONString(), PromotionSupplier.class);
//            for (PromotionSupplier newEntity : newPromotionSuppliers) {
//                //                newEntity.setTenantId(tenantId);
//                newEntity.setTenantId(null);
//                for (PromotionSupplier oldEntity : oldPromotionSuppliers) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        promotionSupplierMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    promotionSupplierMapper.insertSelective(newEntity);
//                }
//            }
//            //商品扩展
//            MaterialPropertyExample materialPropertyExample = new MaterialPropertyExample();
//            materialPropertyExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<MaterialProperty> oldMaterialProperties = materialPropertyMapper.selectByExample(materialPropertyExample);
//            List<MaterialProperty> newMaterialProperties = JSONObject.parseArray(newJsonObject.getJSONArray("materialProperties").toJSONString(), MaterialProperty.class);
//            for (MaterialProperty newEntity: newMaterialProperties){
//                for (MaterialProperty oldEntity :oldMaterialProperties){
//                    if (newEntity.getId().equals(oldEntity.getId())){
//                        materialPropertyMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    materialPropertyMapper.insertSelective(newEntity);
//                }
//            }
//            //消息
//            MsgExample msgExample = new MsgExample();
//            msgExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<Msg> oldMsgs = msgMapper.selectByExample(msgExample);
//            List<Msg> newMsgs = JSONObject.parseArray(newJsonObject.getJSONArray("msgs").toJSONString(), Msg.class);
//            for (Msg newEntity : newMsgs) {
//                //                newEntity.setTenantId(tenantId);
//                newEntity.setTenantId(null);
//                for (Msg oldEntity : oldMsgs) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        msgMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    msgMapper.insertSelective(newEntity);
//                }
//            }
            //机构用户关系
//            OrgaUserRelExample orgaUserRelExample = new OrgaUserRelExample();
//            orgaUserRelExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<OrgaUserRel> oldOrgaUserRels = orgaUserRelMapper.selectByExample(orgaUserRelExample);
//            List<OrgaUserRel> newOrgaUserRels = JSONObject.parseArray(newJsonObject.getJSONArray("orgaUserRels").toJSONString(), OrgaUserRel.class);
//            for (OrgaUserRel newEntity : newOrgaUserRels) {
//                //                newEntity.setTenantId(tenantId);
//                newEntity.setTenantId(null);
//                for (OrgaUserRel oldEntity : oldOrgaUserRels) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        orgaUserRelMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    orgaUserRelMapper.insertSelective(newEntity);
//                }
//            }
//            //机构表
//            OrganizationExample organizationExample = new OrganizationExample();
//            organizationExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<Organization> oldOrganizations = organizationMapper.selectByExample(organizationExample);
//            List<Organization> newOrganizations = JSONObject.parseArray(newJsonObject.getJSONArray("organizations").toJSONString(), Organization.class);
//            for (Organization newEntity : newOrganizations) {
//                //                newEntity.setTenantId(tenantId);
//                newEntity.setTenantId(null);
//                for (Organization oldEntity : oldOrganizations) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        organizationMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    organizationMapper.insertSelective(newEntity);
//                }
//            }
//            //经手人
//            PersonExample personExample = new PersonExample();
//            personExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<Person> oldPersons = personMapper.selectByExample(personExample);
//            List<Person> newPersons = JSONObject.parseArray(newJsonObject.getJSONArray("persons").toJSONString(), Person.class);
//            for (Person newEntity : newPersons) {
//                //                newEntity.setTenantId(tenantId);
//                newEntity.setTenantId(null);
//                for (Person oldEntity : oldPersons) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        personMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    personMapper.insertSelective(newEntity);
//                }
//            }
//            //返利表头
//            RebateExample rebateExample = new RebateExample();
//            rebateExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<Rebate> oldRebates = rebateMapper.selectByExample(rebateExample);
//            List<Rebate> newRebates = JSONObject.parseArray(newJsonObject.getJSONArray("rebates").toJSONString(), Rebate.class);
//            for (Rebate newEntity : newRebates) {
//                //                newEntity.setTenantId(tenantId);
//                newEntity.setTenantId(null);
//                for (Rebate oldEntity : oldRebates) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        rebateMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    rebateMapper.insertSelective(newEntity);
//                }
//            }
//            //返利表体
//            RebateItemExample rebateItemExample = new RebateItemExample();
//            rebateItemExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<RebateItem> oldRebateItems = rebateItemMapper.selectByExample(rebateItemExample);
//            List<RebateItem> newRebateItems = JSONObject.parseArray(newJsonObject.getJSONArray("rebateItems").toJSONString(), RebateItem.class);
//            for (RebateItem newEntity : newRebateItems) {
////               //                newEntity.setTenantId(tenantId);
//                for (RebateItem oldEntity : oldRebateItems) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        rebateItemMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    rebateItemMapper.insertSelective(newEntity);
//                }
//            }
//            //返利商品
//            RebateMaterialExample rebateMaterialExample = new RebateMaterialExample();
//            rebateMaterialExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<RebateMaterial> oldRebateMaterials = rebateMaterialMapper.selectByExample(rebateMaterialExample);
//            List<RebateMaterial> newRebateMaterials = JSONObject.parseArray(newJsonObject.getJSONArray("rebateMaterials").toJSONString(), RebateMaterial.class);
//            for (RebateMaterial newEntity : newRebateMaterials) {
////               //                newEntity.setTenantId(tenantId);
//                for (RebateMaterial oldEntity : oldRebateMaterials) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        rebateMaterialMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    rebateMaterialMapper.insertSelective(newEntity);
//                }
//            }
//            //返利规则
//            RebateRuleExample rebateRuleExample = new RebateRuleExample();
//            rebateRuleExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<RebateRule> oldRebateRules = rebateRuleMapper.selectByExample(rebateRuleExample);
//            List<RebateRule> newRebateRules = JSONObject.parseArray(newJsonObject.getJSONArray("rebateRules").toJSONString(), RebateRule.class);
//            for (RebateRule newEntity : newRebateRules) {
////               //                newEntity.setTenantId(tenantId);
//                for (RebateRule oldEntity : oldRebateRules) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        rebateRuleMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    rebateRuleMapper.insertSelective(newEntity);
//                }
//            }
//            //角色
//            RoleExample roleExample = new RoleExample();
//            roleExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<Role> oldRoles = roleMapper.selectByExample(roleExample);
//            List<Role> newRoles = JSONObject.parseArray(newJsonObject.getJSONArray("roles").toJSONString(), Role.class);
//            for (Role newEntity : newRoles) {
//                //                newEntity.setTenantId(tenantId);
//                newEntity.setTenantId(null);
//                for (Role oldEntity : oldRoles) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        roleMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    roleMapper.insertSelective(newEntity);
//                }
//            }
//            //序列号
//            SerialNumberExample serialNumberExample = new SerialNumberExample();
//            serialNumberExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<SerialNumber> oldSerialNumbers = serialNumberMapper.selectByExample(serialNumberExample);
//            List<SerialNumber> newSerialNumbers = JSONObject.parseArray(newJsonObject.getJSONArray("serialNumbers").toJSONString(), SerialNumber.class);
//            for (SerialNumber newEntity : newSerialNumbers) {
//                //                newEntity.setTenantId(tenantId);
//                newEntity.setTenantId(null);
//                for (SerialNumber oldEntity : oldSerialNumbers) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        serialNumberMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    serialNumberMapper.insertSelective(newEntity);
//                }
//            }
//            //供应商/客户
//            SupplierExample supplierExample = new SupplierExample();
//            supplierExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<Supplier> oldSuppliers = supplierMapper.selectByExample(supplierExample);
//            List<Supplier> newSuppliers = JSONObject.parseArray(newJsonObject.getJSONArray("suppliers").toJSONString(), Supplier.class);
//            for (Supplier newEntity : newSuppliers) {
//                //                newEntity.setTenantId(tenantId);
//                newEntity.setTenantId(null);
//                for (Supplier oldEntity : oldSuppliers) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        supplierMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    supplierMapper.insertSelective(newEntity);
//                }
//            }
//            //系统参数
//            SystemConfigExample systemConfigExample = new SystemConfigExample();
//            systemConfigExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<SystemConfig> oldSystemConfigs = systemConfigMapper.selectByExample(systemConfigExample);
//            List<SystemConfig> newSystemConfigs = JSONObject.parseArray(newJsonObject.getJSONArray("systemConfigs").toJSONString(), SystemConfig.class);
//            for (SystemConfig newEntity : newSystemConfigs) {
//                //                newEntity.setTenantId(tenantId);
//                newEntity.setTenantId(null);
//                for (SystemConfig oldEntity : oldSystemConfigs) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        systemConfigMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    systemConfigMapper.insertSelective(newEntity);
//                }
//            }
//            //租户
//            List<Tenant> oldTenants = tenantMapper.selectByExample(new TenantExample());
//            newJsonObject.get("tenants");
//            List<Tenant> newTenants = JSONObject.parseArray(newJsonObject.getJSONArray("tenants").toJSONString(), Tenant.class);
//            for (Tenant newEntity : newTenants) {
//                //                newEntity.setTenantId(tenantId);
//                newEntity.setTenantId(null);
//                for (Tenant oldEntity : oldTenants) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        tenantMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    tenantMapper.insertSelective(newEntity);
//                }
//            }
//            //单位
//            UnitExample unitExample = new UnitExample();
//            unitExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<Unit> oldUnits = unitMapper.selectByExample(unitExample);
//            List<Unit> newUnits = JSONObject.parseArray(newJsonObject.getJSONArray("units").toJSONString(), Unit.class);
//            for (Unit newEntity : newUnits) {
//                //                newEntity.setTenantId(tenantId);
//                newEntity.setTenantId(null);
//                for (Unit oldEntity : oldUnits) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        unitMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    unitMapper.insertSelective(newEntity);
//                }
//            }
//            //用户
//            List<User> oldUsers = userMapper.selectByExample(new UserExample());
//            newJsonObject.get("users");
//            List<User> newUsers = JSONObject.parseArray(newJsonObject.getJSONArray("users").toJSONString(), User.class);
//            for (User newEntity : newUsers) {
//                //                newEntity.setTenantId(tenantId);
//                newEntity.setTenantId(null);
//                for (User oldEntity : oldUsers) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        userMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    userMapper.insertSelective(newEntity);
//                }
//            }
//            //用户-角色-模块关系
//            UserBusinessExample userBusinessExample = new UserBusinessExample();
//            userBusinessExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<UserBusiness> oldUserBusinesses = userBusinessMapper.selectByExample(userBusinessExample);
//            List<UserBusiness> newUserBusinesses = JSONObject.parseArray(newJsonObject.getJSONArray("userBusinesses").toJSONString(), UserBusiness.class);
//            for (UserBusiness newEntity : newUserBusinesses) {
//                //                newEntity.setTenantId(tenantId);
//                newEntity.setTenantId(null);
//                for (UserBusiness oldEntity : oldUserBusinesses) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        userBusinessMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    userBusinessMapper.insertSelective(newEntity);
//                }
//            }
//            //用户类型
//            UserCategoryExample userCategoryExample = new UserCategoryExample();
//            userCategoryExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<UserCategory> oldUserCategories = userCategoryMapper.selectByExample(userCategoryExample);
//            List<UserCategory> newUserCategories = JSONObject.parseArray(newJsonObject.getJSONArray("userCategories").toJSONString(), UserCategory.class);
//            for (UserCategory newEntity : newUserCategories) {
//                //                newEntity.setTenantId(tenantId);
//                newEntity.setTenantId(null);
//                for (UserCategory oldEntity : oldUserCategories) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        userCategoryMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    userCategoryMapper.insertSelective(newEntity);
//                }
//            }
//            //审批明细
//            WorkflowApproveDetailExample workflowApproveDetailExample = new WorkflowApproveDetailExample();
//            workflowApproveDetailExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<WorkflowApproveDetail> oldWorkflowApproveDetails = workflowApproveDetailMapper.selectByExample(workflowApproveDetailExample);
//            List<WorkflowApproveDetail> newWorkflowApproveDetails = JSONObject.parseArray(newJsonObject.getJSONArray("workflowApproveDetails").toJSONString(), WorkflowApproveDetail.class);
//            for (WorkflowApproveDetail newEntity : newWorkflowApproveDetails) {
//                //                newEntity.setTenantId(tenantId);
//                newEntity.setTenantId(null);
//                for (WorkflowApproveDetail oldEntity : oldWorkflowApproveDetails) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        workflowApproveDetailMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    workflowApproveDetailMapper.insertSelective(newEntity);
//                }
//            }
//            //配置明细
//            WorkflowConfigDetailExample workflowConfigDetailExample = new WorkflowConfigDetailExample();
//            workflowConfigDetailExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<WorkflowConfigDetail> oldWorkflowConfigDetails = workflowConfigDetailMapper.selectByExample(workflowConfigDetailExample);
//            List<WorkflowConfigDetail> newWorkflowConfigDetails = JSONObject.parseArray(newJsonObject.getJSONArray("workflowConfigDetails").toJSONString(), WorkflowConfigDetail.class);
//            for (WorkflowConfigDetail newEntity : newWorkflowConfigDetails) {
//                //                newEntity.setTenantId(tenantId);
//                newEntity.setTenantId(null);
//                for (WorkflowConfigDetail oldEntity : oldWorkflowConfigDetails) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        workflowConfigDetailMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    workflowConfigDetailMapper.insertSelective(newEntity);
//                }
//            }
//            //配置主表
//            WorkflowConfigMainExample workflowConfigMainExample = new WorkflowConfigMainExample();
//            workflowConfigMainExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<WorkflowConfigMain> oldWorkflowConfigMains = workflowConfigMainMapper.selectByExample(workflowConfigMainExample);
//            List<WorkflowConfigMain> newWorkflowConfigMains = JSONObject.parseArray(newJsonObject.getJSONArray("workflowConfigMains").toJSONString(), WorkflowConfigMain.class);
//            for (WorkflowConfigMain newEntity : newWorkflowConfigMains) {
//                //                newEntity.setTenantId(tenantId);
//                newEntity.setTenantId(null);
//                for (WorkflowConfigMain oldEntity : oldWorkflowConfigMains) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        workflowConfigMainMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    workflowConfigMainMapper.insertSelective(newEntity);
//                }
//            }
//            //处理详情
//            WorkflowProcessDetailExample workflowProcessDetailExample = new WorkflowProcessDetailExample();
//            workflowProcessDetailExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<WorkflowProcessDetail> oldProcessDetails = workflowProcessDetailMapper.selectByExample(workflowProcessDetailExample);
//            List<WorkflowProcessDetail> newProcessDetails = JSONObject.parseArray(newJsonObject.getJSONArray("processDetails").toJSONString(), WorkflowProcessDetail.class);
//            for (WorkflowProcessDetail newEntity : newProcessDetails) {
//                //                newEntity.setTenantId(tenantId);
//                newEntity.setTenantId(null);
//                for (WorkflowProcessDetail oldEntity : oldProcessDetails) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        workflowProcessDetailMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    workflowProcessDetailMapper.insertSelective(newEntity);
//                }
//            }
//            //处理详情历史记录
//            WorkflowProcessDetailHisExample workflowProcessDetailHisExample = new WorkflowProcessDetailHisExample();
//            workflowProcessDetailHisExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<WorkflowProcessDetailHis> oldProcessDetailHis = workflowProcessDetailHisMapper.selectByExample(workflowProcessDetailHisExample);
//            List<WorkflowProcessDetailHis> newProcessDetailHis = JSONObject.parseArray(newJsonObject.getJSONArray("processDetailHis").toJSONString(), WorkflowProcessDetailHis.class);
//            for (WorkflowProcessDetailHis newEntity : newProcessDetailHis) {
//                //                newEntity.setTenantId(tenantId);
//                newEntity.setTenantId(null);
//                for (WorkflowProcessDetailHis oldEntity : oldProcessDetailHis) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        workflowProcessDetailHisMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    workflowProcessDetailHisMapper.insertSelective(newEntity);
//                }
//            }
        } catch (Exception e) {
            JshException.writeFail(logger, e, this.getLanCode());
        }
    }

    /**
     * @Author: wy
     * @Description: 查询总店新商品
     * @DateTime: 2022-08-23 17:26
     * @Params:
     * @Return
     */
    public JSONObject getMaterialInfoNewJsonObject(List<String> idList) {
        JSONObject oldJsonObject = new JSONObject();
        Map<String, List<DepotItem>> applyDepotMap = new HashMap<>();
        Map<String, List<DepotItem>> deliveryDepotMap = new HashMap<>();
        Map<String, List<Attachment>> attachmentMap = new HashMap<>();
        Map<String, List<MaterialExtend>> materialExtendMap = new HashMap<>();
        Map<String, Unit> unitMap = new HashMap<>();
        //商品
        MaterialExample materialExample = new MaterialExample();
        materialExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
        List<Material> materials = materialMapper.selectByExample(materialExample);
        oldJsonObject.put("materials", materials);
        if (materials.size() > 0) {
            for (Material material : materials) {
                //单位
                Unit unit = unitMapper.selectByPrimaryKey(material.getUnitId());
                unitMap.put(material.getId(), unit);
                //图片
//                AttachmentExample example = new AttachmentExample();
//                example.createCriteria().andHeaderIdEqualTo(material.getId()).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//                List<Attachment> attachments = attachmentMapper.selectByExample(example);
//                attachmentMap.put(material.getId(), attachments);
                //商品价格
                MaterialExtendExample materialExtendExample = new MaterialExtendExample();
                materialExtendExample.createCriteria().andMaterialIdEqualTo(material.getId()).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
                List<MaterialExtend> materialExtends = materialExtendMapper.selectByExample(materialExtendExample);
                materialExtendMap.put(material.getId(), materialExtends);
            }
        }
        oldJsonObject.put("materialExtendMap", materialExtendMap);
        oldJsonObject.put("attachmentMap", attachmentMap);
        oldJsonObject.put("unitMap", unitMap);
        //商品类型
        MaterialCategoryExample materialCategoryExample = new MaterialCategoryExample();
        materialCategoryExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
        List<MaterialCategory> materialCategories = materialCategoryMapper.selectByExample(materialCategoryExample);
        oldJsonObject.put("materialCategories", materialCategories);
        //要货申请
        DepotHeadExample applyExample = new DepotHeadExample();
        applyExample.createCriteria().andSubTypeEqualTo("要货申请").andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andAnotherDepotIdIn(idList);
        List<DepotHead> applyDepotHead = depotHeadMapper.selectByExample(applyExample);
        if (applyDepotHead.size() > 0) {
            for (DepotHead depotHead : applyDepotHead) {
                //单位
                DepotItemExample depotItemExample = new DepotItemExample();
                depotItemExample.createCriteria().andHeaderIdEqualTo(depotHead.getId()).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
                List<DepotItem> depotItems = depotItemMapper.selectByExample(depotItemExample);
                applyDepotMap.put(depotHead.getId(), depotItems);
            }
        }
        oldJsonObject.put("applyDepotMap", applyDepotMap);
        oldJsonObject.put("applyDepotHead", applyDepotHead);
        //配送
        DepotHeadExample deliveryExample = new DepotHeadExample();
        deliveryExample.createCriteria().andSubTypeEqualTo("配送").andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED).andAnotherDepotIdIn(idList);
        List<DepotHead> deliveryDepotHead = depotHeadMapper.selectByExample(deliveryExample);
        if (deliveryDepotHead.size() > 0) {
            for (DepotHead depotHead : deliveryDepotHead) {
                //单位
                DepotItemExample depotItemExample = new DepotItemExample();
                depotItemExample.createCriteria().andHeaderIdEqualTo(depotHead.getId()).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
                List<DepotItem> depotItems = depotItemMapper.selectByExample(depotItemExample);
                deliveryDepotMap.put(depotHead.getId(), depotItems);
            }
        }
        oldJsonObject.put("deliveryDepotMap", deliveryDepotMap);
        oldJsonObject.put("deliveryDepotHead", deliveryDepotHead);

        //仓库
        DepotExample depotExample = new DepotExample();
        depotExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
        List<Depot> depots = depotMapper.selectByExample(depotExample);
        oldJsonObject.put("depots", depots);

        //用户
        List<User> users = userMapper.selectByExample(new UserExample());
        oldJsonObject.put("users", users);

        return oldJsonObject;
    }

    public JSONObject getInfoNewJsonObject(List<String> idList) {
        JSONObject oldJsonObject = new JSONObject();
        Map<String, List<DepotItem>> applyDepotMap = new HashMap<>();
        Map<String, List<DepotItem>> deliveryDepotMap = new HashMap<>();
        Map<String, List<DepotItem>> acceptanceDepotMap = new HashMap<>();
        Map<String, List<DepotItem>> purchaseDepotMap = new HashMap<>();
        Map<String, List<DepotItem>> checkDepotMap = new HashMap<>();
        Map<String, List<AccountItem>> accountDepotMap = new HashMap<>();
        Map<String, List<AccountItem>> outAccountDepotMap = new HashMap<>();
        Map<String, List<Attachment>> attachmentMap = new HashMap<>();
        //要货申请
        List<DepotHead> applyDepotHead = depotHeadMapperEx.selectInfoDepotHead("要货申请", idList);
        if (applyDepotHead.size() > 0) {
            for (DepotHead depotHead : applyDepotHead) {
                //单位
                DepotItemExample depotItemExample = new DepotItemExample();
                depotItemExample.createCriteria().andHeaderIdEqualTo(depotHead.getId());
                List<DepotItem> depotItems = depotItemMapper.selectByExample(depotItemExample);
                applyDepotMap.put(depotHead.getId(), depotItems);
                //附件
                AttachmentExample example = new AttachmentExample();
                example.createCriteria().andHeaderIdEqualTo(depotHead.getId());
                List<Attachment> attachments = attachmentMapper.selectByExample(example);
                attachmentMap.put(depotHead.getId(), attachments);
            }
        }
        oldJsonObject.put("applyDepotMap", applyDepotMap);
        oldJsonObject.put("applyDepotHead", applyDepotHead);
        //配送
        List<DepotHead> deliveryDepotHead = depotHeadMapperEx.selectDeliveryDepotHead("配送", idList);
        if (deliveryDepotHead.size() > 0) {
            for (DepotHead depotHead : deliveryDepotHead) {
                //单位
                DepotItemExample depotItemExample = new DepotItemExample();
                depotItemExample.createCriteria().andHeaderIdEqualTo(depotHead.getId());
                List<DepotItem> depotItems = depotItemMapper.selectByExample(depotItemExample);
                deliveryDepotMap.put(depotHead.getId(), depotItems);
                //附件
                AttachmentExample example = new AttachmentExample();
                example.createCriteria().andHeaderIdEqualTo(depotHead.getId());
                List<Attachment> attachments = attachmentMapper.selectByExample(example);
                attachmentMap.put(depotHead.getId(), attachments);
            }
        }
        oldJsonObject.put("deliveryDepotMap", deliveryDepotMap);
        oldJsonObject.put("deliveryDepotHead", deliveryDepotHead);
        //验收
        List<DepotHead> acceptanceDepotHead = depotHeadMapperEx.selectInfoDepotHead("验收", idList);
        if (acceptanceDepotHead.size() > 0) {
            for (DepotHead depotHead : acceptanceDepotHead) {
                //单位
                DepotItemExample depotItemExample = new DepotItemExample();
                depotItemExample.createCriteria().andHeaderIdEqualTo(depotHead.getId());
                List<DepotItem> depotItems = depotItemMapper.selectByExample(depotItemExample);
                acceptanceDepotMap.put(depotHead.getId(), depotItems);
                //附件
                AttachmentExample example = new AttachmentExample();
                example.createCriteria().andHeaderIdEqualTo(depotHead.getId());
                List<Attachment> attachments = attachmentMapper.selectByExample(example);
                attachmentMap.put(depotHead.getId(), attachments);
            }
        }
        oldJsonObject.put("acceptanceDepotMap", acceptanceDepotMap);
        oldJsonObject.put("acceptanceDepotHead", acceptanceDepotHead);

        //采购订单
        List<DepotHead> purchaseDepotHead = depotHeadMapperEx.selectPurchaseDepotHead("采购订单", idList);
        if (purchaseDepotHead.size() > 0) {
            for (DepotHead depotHead : purchaseDepotHead) {
                //单位
                DepotItemExample depotItemExample = new DepotItemExample();
                depotItemExample.createCriteria().andHeaderIdEqualTo(depotHead.getId()).andUploadFlagEqualTo("0");
                List<DepotItem> depotItems = depotItemMapper.selectByExample(depotItemExample);
                purchaseDepotMap.put(depotHead.getId(), depotItems);
                //附件
                AttachmentExample example = new AttachmentExample();
                example.createCriteria().andHeaderIdEqualTo(depotHead.getId()).andUploadFlagEqualTo("0");
                List<Attachment> attachments = attachmentMapper.selectByExample(example);
                attachmentMap.put(depotHead.getId(), attachments);
            }
        }
        oldJsonObject.put("purchaseDepotMap", purchaseDepotMap);
        oldJsonObject.put("purchaseDepotHead", purchaseDepotHead);


        Map<String, List<DepotItem>> quotationDepotMap = new HashMap<>();
        //厂家报价
        List<DepotHead> quotationDepotHead = synchronizationTaskMapperEx.selectDepotHeadByLinkNumberNotTenantId( "厂家报价", idList);
        if (quotationDepotHead.size() > 0) {
            for (DepotHead quotationHead : quotationDepotHead) {
                //单位
//                        List<DepotItem> depotItems = synchronizationTaskMapperEx.selectDepotItemByHid(quotationHead.getId());
                DepotItemExample depotItemExample = new DepotItemExample();
                depotItemExample.createCriteria().andHeaderIdEqualTo(quotationHead.getId()).andUploadFlagEqualTo("0");
                List<DepotItem> depotItems = depotItemMapper.selectByExample(depotItemExample);
                quotationDepotMap.put(quotationHead.getId(), depotItems);
                //附件
                AttachmentExample example = new AttachmentExample();
                example.createCriteria().andHeaderIdEqualTo(quotationHead.getId()).andUploadFlagEqualTo("0");
                List<Attachment> attachments = attachmentMapper.selectByExample(example);
                attachmentMap.put(quotationHead.getId(), attachments);
            }
        }
        oldJsonObject.put("quotationDepotMap", quotationDepotMap);
        oldJsonObject.put("quotationDepotHead", quotationDepotHead);


//        //付款凭证
//        List<String> typeList=new ArrayList<>();
//        typeList.add("付款");
//        typeList.add("预付款单");
//        typeList.add("运输付款");
////        typeList.add("直发付款");
////        typeList.add("直发预付款");
////        typeList.add("直发运输付款");
//        List<AccountHead> accountHeads = synchronizationTaskMapperEx.selectAccountHeadByDepot(typeList, idList);
//        if (accountHeads.size() > 0) {
//            for (AccountHead accountHead : accountHeads) {
//                //明细
//                AccountItemExample accountItemExample = new AccountItemExample();
//                accountItemExample.createCriteria().andHeaderIdEqualTo(accountHead.getId()).andUploadFlagEqualTo("0");
//                List<AccountItem> accountItems = accountItemMapper.selectByExample(accountItemExample);
//                accountDepotMap.put(accountHead.getId(), accountItems);
//                //附件
//                AttachmentExample example = new AttachmentExample();
//                example.createCriteria().andHeaderIdEqualTo(accountHead.getId()).andUploadFlagEqualTo("0");
//                List<Attachment> attachments = attachmentMapper.selectByExample(example);
//                attachmentMap.put(accountHead.getId(), attachments);
//            }
//        }
//        oldJsonObject.put("accountDepotMap", accountDepotMap);
//        oldJsonObject.put("accountHeads", accountHeads);

//        收款
        List<String> outTypeList=new ArrayList<>();
        outTypeList.add("预收款");
        List<AccountHead> outAccountHeads = synchronizationTaskMapperEx.selectAccountHeadByType(outTypeList);
        if (outAccountHeads.size() > 0) {
            for (AccountHead accountHead : outAccountHeads) {
//                //明细
//                AccountItemExample accountItemExample = new AccountItemExample();
//                accountItemExample.createCriteria().andHeaderIdEqualTo(accountHead.getId()).andUploadFlagEqualTo("0");
//                List<AccountItem> accountItems = accountItemMapper.selectByExample(accountItemExample);
//                outAccountDepotMap.put(accountHead.getId(), accountItems);
                //附件
                AttachmentExample example = new AttachmentExample();
                example.createCriteria().andHeaderIdEqualTo(accountHead.getId()).andUploadFlagEqualTo("0");
                List<Attachment> attachments = attachmentMapper.selectByExample(example);
                attachmentMap.put(accountHead.getId(), attachments);
            }
        }
//        oldJsonObject.put("outAccountDepotMap", outAccountDepotMap);
        oldJsonObject.put("outAccountHeads", outAccountHeads);

        //盘点
        List<DepotHead> checkDepotHead = synchronizationTaskMapperEx.selectCheckDepotHead("盘点单", idList);
        if (checkDepotHead.size() > 0) {
            for (DepotHead depotHead : checkDepotHead) {
                //单位
                DepotItemExample depotItemExample = new DepotItemExample();
                depotItemExample.createCriteria().andHeaderIdEqualTo(depotHead.getId()).andUploadFlagEqualTo("0");
                List<DepotItem> depotItems = depotItemMapper.selectByExample(depotItemExample);
                checkDepotMap.put(depotHead.getId(), depotItems);
                //附件
                AttachmentExample example = new AttachmentExample();
                example.createCriteria().andHeaderIdEqualTo(depotHead.getId()).andUploadFlagEqualTo("0");
                List<Attachment> attachments = attachmentMapper.selectByExample(example);
                attachmentMap.put(depotHead.getId(), attachments);
            }

        }
        oldJsonObject.put("checkDepotMap", checkDepotMap);
        oldJsonObject.put("checkDepotHead", checkDepotHead);

        Map<String, List<DepotItem>> otherDepotMap = new HashMap<>();
        //其它出入库
        List<DepotHead> otherDepotHead = synchronizationTaskMapperEx.selectDepotHeadByLinkNumberNotTenantId("其它", idList);
        if (otherDepotHead.size() > 0) {
            for (DepotHead quotationHead : otherDepotHead) {
                //单位
                DepotItemExample depotItemExample = new DepotItemExample();
                depotItemExample.createCriteria().andHeaderIdEqualTo(quotationHead.getId()).andUploadFlagEqualTo("0");
                List<DepotItem> depotItems = depotItemMapper.selectByExample(depotItemExample);
                otherDepotMap.put(quotationHead.getId(), depotItems);
                //附件
                AttachmentExample example = new AttachmentExample();
                example.createCriteria().andHeaderIdEqualTo(quotationHead.getId()).andUploadFlagEqualTo("0");
                List<Attachment> attachments = attachmentMapper.selectByExample(example);
                attachmentMap.put(quotationHead.getId(), attachments);
            }
        }
        oldJsonObject.put("otherDepotMap", otherDepotMap);
        oldJsonObject.put("otherDepotHead", otherDepotHead);


        oldJsonObject.put("attachmentMap", attachmentMap);
        return oldJsonObject;
    }

    public JSONObject getUpInfoNewJsonObject() {
        JSONObject oldJsonObject = new JSONObject();
        Map<String, List<DepotItem>> applyDepotMap = new HashMap<>();
        Map<String, List<DepotItem>> deliveryDepotMap = new HashMap<>();
        Map<String, List<DepotItem>> acceptanceDepotMap = new HashMap<>();
        Map<String, List<Attachment>> attachmentMap = new HashMap<>();
        //要货申请
        List<DepotHead> applyDepotHead = synchronizationTaskMapperEx.selectDepotHeadByType(tenantId, "要货申请");
        if (applyDepotHead.size() > 0) {
            for (DepotHead depotHead : applyDepotHead) {
                //单位
                List<DepotItem> depotItems = synchronizationTaskMapperEx.selectDepotItemByHid(tenantId, depotHead.getId());
                applyDepotMap.put(depotHead.getId(), depotItems);
                //附件
                List<Attachment> attachments = synchronizationTaskMapperEx.selectAttachmentByHid(tenantId, depotHead.getId());
                attachmentMap.put(depotHead.getId(), attachments);
            }
        }
        oldJsonObject.put("applyDepotMap", applyDepotMap);
        oldJsonObject.put("applyDepotHead", applyDepotHead);
        //配送
        List<DepotHead> deliveryDepotHead = synchronizationTaskMapperEx.selectDepotHeadByType(tenantId, "配送");
        if (deliveryDepotHead.size() > 0) {
            for (DepotHead depotHead : deliveryDepotHead) {
                //单位
                List<DepotItem> depotItems = synchronizationTaskMapperEx.selectDepotItemByHid(tenantId, depotHead.getId());
                deliveryDepotMap.put(depotHead.getId(), depotItems);
                //附件
                List<Attachment> attachments = synchronizationTaskMapperEx.selectAttachmentByHid(tenantId, depotHead.getId());
                attachmentMap.put(depotHead.getId(), attachments);
            }
        }
        oldJsonObject.put("deliveryDepotMap", deliveryDepotMap);
        oldJsonObject.put("deliveryDepotHead", deliveryDepotHead);
        //验收
        List<DepotHead> acceptanceDepotHead = synchronizationTaskMapperEx.selectDepotHeadByType(tenantId, "验收");
        if (acceptanceDepotHead.size() > 0) {
            for (DepotHead depotHead : acceptanceDepotHead) {
                //单位
                List<DepotItem> depotItems = synchronizationTaskMapperEx.selectDepotItemByHid(tenantId, depotHead.getId());
                acceptanceDepotMap.put(depotHead.getId(), depotItems);
                //附件
                List<Attachment> attachments = synchronizationTaskMapperEx.selectAttachmentByHid(tenantId, depotHead.getId());
                attachmentMap.put(depotHead.getId(), attachments);
            }
        }
        oldJsonObject.put("acceptanceDepotMap", acceptanceDepotMap);
        oldJsonObject.put("acceptanceDepotHead", acceptanceDepotHead);
        oldJsonObject.put("attachmentMap", attachmentMap);

        Map<String, List<DepotItem>> purchaseDepotMap = new HashMap<>();
//        Map<String, List<DepotItem>> quotationDepotMap = new HashMap<>();
        Map<String, List<DepotItem>> stockInDepotMap = new HashMap<>();

        //采购订单
        List<DepotHead> purchaseDepotHead = synchronizationTaskMapperEx.selectDepotHeadByStatus(tenantId, "采购订单", "2");
        if (null != purchaseDepotHead && purchaseDepotHead.size() > 0) {

            for (DepotHead depotHead : purchaseDepotHead) {
                //单位
                List<DepotItem> depotItems = synchronizationTaskMapperEx.selectDepotItemByHid(tenantId, depotHead.getId());
                purchaseDepotMap.put(depotHead.getId(), depotItems);
                //附件
                List<Attachment> attachments = synchronizationTaskMapperEx.selectAttachmentByHid(tenantId, depotHead.getId());
                attachmentMap.put(depotHead.getId(), attachments);
            }
            List<String> purchaseNumberList= purchaseDepotHead.stream()
                    .map(DepotHead::getNumber).collect(Collectors.toList());
            if (purchaseNumberList.size() > 0){

//                oldJsonObject.put("quotationDepotMap", quotationDepotMap);
//                oldJsonObject.put("quotationDepotHead", quotationDepotHead);
//                oldJsonObject.put("attachmentMap", attachmentMap);
                //采购
                List<DepotHead> stockInDepotHead = synchronizationTaskMapperEx.selectDepotHeadByLinkNumber(tenantId, "采购", purchaseNumberList);
                if (stockInDepotHead.size() > 0) {
                    for (DepotHead stockInHead : stockInDepotHead) {
                        //单位
                        List<DepotItem> depotItems = synchronizationTaskMapperEx.selectDepotItemByHid(tenantId, stockInHead.getId());
                        stockInDepotMap.put(stockInHead.getId(), depotItems);
                        //附件
                        List<Attachment> attachments = synchronizationTaskMapperEx.selectAttachmentByHid(tenantId, stockInHead.getId());
                        attachmentMap.put(stockInHead.getId(), attachments);
                    }
                }
                //采购入库
                oldJsonObject.put("stockInDepotMap", stockInDepotMap);
                oldJsonObject.put("stockInDepotHead", stockInDepotHead);
                oldJsonObject.put("attachmentMap", attachmentMap);
            }

        }
        //采购订单
        oldJsonObject.put("purchaseDepotMap", purchaseDepotMap);
        oldJsonObject.put("purchaseDepotHead", purchaseDepotHead);
        Map<String, List<DepotItem>> purchaseReturnDepotMap = new HashMap<>();
        //采购退货
        List<DepotHead> purchaseReturnList = synchronizationTaskMapperEx.selectDepotHeadByStatus(tenantId, "采购退货", null);
        if (null != purchaseReturnList && purchaseReturnList.size() > 0) {

            for (DepotHead depotHead : purchaseReturnList) {
                //单位
                List<DepotItem> depotItems = synchronizationTaskMapperEx.selectDepotItemByHid(tenantId, depotHead.getId());
                purchaseReturnDepotMap.put(depotHead.getId(), depotItems);
                //附件
                List<Attachment> attachments = synchronizationTaskMapperEx.selectAttachmentByHid(tenantId, depotHead.getId());
                attachmentMap.put(depotHead.getId(), attachments);
            }
        }
        oldJsonObject.put("purchaseReturnDepotMap", purchaseReturnDepotMap);
        oldJsonObject.put("purchaseReturnList", purchaseReturnList);
        oldJsonObject.put("attachmentMap", attachmentMap);
        return oldJsonObject;
    }


    /**
     * @Author: wy
     * @Description: 下载总店新商品
     * @DateTime: 2022-08-23 17:26
     * @Params:
     * @Return
     */
    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    public void synchronizationMaterial(JSONObject newJsonObject, String tenantId) {
        try {
            //商品
            MaterialExample materialExample = new MaterialExample();
            materialExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
            List<Material> oldMaterials = materialMapper.selectByExample(materialExample);
            List<Material> newMaterials = JSONObject.parseArray(newJsonObject.getJSONArray("materials").toJSONString(), Material.class);

            Map<String, Unit> unitMap = JSONObject.parseObject(newJsonObject.getJSONObject("unitMap").toJSONString(), new TypeReference<Map<String, Unit>>() {
            });

            Map<String, List<Attachment>> attachmentMap = JSONObject.parseObject(newJsonObject.getJSONObject("attachmentMap").toJSONString())
                    .entrySet().stream()
                    .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), Attachment.class)));

            Map<String, List<MaterialExtend>> materialExtendMap = JSONObject.parseObject(newJsonObject.getJSONObject("materialExtendMap").toJSONString())
                    .entrySet().stream()
                    .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), MaterialExtend.class)));
            for (Material newEntity : newMaterials) {
                //                newEntity.setTenantId(tenantId);
                newEntity.setTenantId(null);
                for (Material oldEntity : oldMaterials) {
                    if (newEntity.getId().equals(oldEntity.getId())) {
                        materialMapperEx.updateByPrimaryKeySelective(newEntity);
                        List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                        if (attachments.size() > 0) {
                            attachmentMapperEx.updateList(attachments);
                        }
                        List<MaterialExtend> materialExtends = materialExtendMap.get(newEntity.getId());
                        if (materialExtends.size() > 0) {
                            materialExtendMapperEx.updateList(materialExtends);
                        }
                        Unit unit = unitMap.get(newEntity.getId());
                        unitMapperEx.updateByPrimaryKeySelective(unit);
                        //新旧数据比对并操作后，将这个数据从List中“移除”
                        newEntity = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newEntity != null) {
                    materialMapperEx.insertSelective(newEntity);
                    List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                    if (attachments.size() > 0) {
                        attachmentMapperEx.insertList(attachments);
                    }
                    List<MaterialExtend> materialExtends = materialExtendMap.get(newEntity.getId());
                    if (materialExtends.size() > 0) {
                        materialExtendMapperEx.insertList(materialExtends);
                    }
                    Unit unit = unitMap.get(newEntity.getId());
                    unitMapperEx.insertSelective(unit);
                }
            }
//            //单位
//            UnitExample unitExample = new UnitExample();
//            unitExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<Unit> oldUnits = unitMapper.selectByExample(unitExample);
//            for (Unit newEntity : newUnits) {
//                //                newEntity.setTenantId(tenantId);
//                newEntity.setTenantId(null);
//                for (Unit oldEntity : oldUnits) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        unitMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    unitMapper.insertSelective(newEntity);
//                }
//            }

            //商品类型
            MaterialCategoryExample materialCategoryExample = new MaterialCategoryExample();
            materialCategoryExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
            List<MaterialCategory> oldMaterialCategories = materialCategoryMapper.selectByExample(materialCategoryExample);
            List<MaterialCategory> newMaterialCategories = JSONObject.parseArray(newJsonObject.getJSONArray("materialCategories").toJSONString(), MaterialCategory.class);
            for (MaterialCategory newEntity : newMaterialCategories) {
                //                newEntity.setTenantId(tenantId);
                newEntity.setTenantId(null);
                for (MaterialCategory oldEntity : oldMaterialCategories) {
                    if (newEntity.getId().equals(oldEntity.getId())) {
                        materialCategoryMapper.updateByPrimaryKeySelective(newEntity);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newEntity = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newEntity != null) {
                    materialCategoryMapper.insertSelective(newEntity);
                }
            }
//            //商品价格
//            MaterialExtendExample materialExtendExample = new MaterialExtendExample();
//            materialExtendExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//            List<MaterialExtend> oldMaterialExtends = materialExtendMapper.selectByExample(materialExtendExample);
//            List<MaterialExtend> newMaterialExtends = JSONObject.parseArray(newJsonObject.getJSONArray("materialExtends").toJSONString(), MaterialExtend.class);
//            for (MaterialExtend newEntity : newMaterialExtends) {
//                //                newEntity.setTenantId(tenantId);
//                newEntity.setTenantId(null);
//                for (MaterialExtend oldEntity : oldMaterialExtends) {
//                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        materialExtendMapper.updateByPrimaryKeySelective(newEntity);
//                        //新旧数据比对并操作后，将新数据从List中“移除”
//                        newEntity = null;
//                        break;
//                    }
//                }
//                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                //没被置null说明这条新数据是新增的，需要调用接口落盘
//                if (newEntity != null) {
//                    materialExtendMapper.insertSelective(newEntity);
//                }
//            }
            //要货申请
            DepotHeadExample applyExample = new DepotHeadExample();
            applyExample.createCriteria().andSubTypeEqualTo("要货申请").andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
            List<DepotHead> oldApplyDepotHead = depotHeadMapper.selectByExample(applyExample);
            List<DepotHead> newApplyDepotHead = JSONObject.parseArray(newJsonObject.getJSONArray("applyDepotHead").toJSONString(), DepotHead.class);
            Map<String, List<DepotItem>> applyDepotMap = JSONObject.parseObject(newJsonObject.getJSONObject("applyDepotMap").toJSONString())
                    .entrySet().stream()
                    .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), DepotItem.class)));

            for (DepotHead newEntity : newApplyDepotHead) {
                //                newEntity.setTenantId(tenantId);
                newEntity.setTenantId(null);
                for (DepotHead oldEntity : oldApplyDepotHead) {
                    if (newEntity.getId().equals(oldEntity.getId())) {
                        depotHeadMapper.updateByPrimaryKeySelective(newEntity);
                        List<DepotItem> depotItems = applyDepotMap.get(newEntity.getId());
                        depotItemMapperEx.updateList(depotItems);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newEntity = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newEntity != null) {
                    depotHeadMapper.insertSelective(newEntity);
                    List<DepotItem> depotItems = applyDepotMap.get(newEntity.getId());
                    depotItemMapperEx.insertList(depotItems);
                }
            }
            DepotHeadExample deliveryExample = new DepotHeadExample();
            deliveryExample.createCriteria().andSubTypeEqualTo("配送").andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
            List<DepotHead> oldDeliveryDepotHead = depotHeadMapper.selectByExample(deliveryExample);
            List<DepotHead> newDeliveryDepotHead = JSONObject.parseArray(newJsonObject.getJSONArray("deliveryDepotHead").toJSONString(), DepotHead.class);
            Map<String, List<DepotItem>> deliveryDepotMap = JSONObject.parseObject(newJsonObject.getJSONObject("deliveryDepotMap").toJSONString())
                    .entrySet().stream()
                    .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), DepotItem.class)));

            for (DepotHead newEntity : newDeliveryDepotHead) {
                //                newEntity.setTenantId(tenantId);
                newEntity.setTenantId(null);
                for (DepotHead oldEntity : oldDeliveryDepotHead) {
                    if (newEntity.getId().equals(oldEntity.getId())) {
                        depotHeadMapper.updateByPrimaryKeySelective(newEntity);
                        List<DepotItem> depotItems = deliveryDepotMap.get(newEntity.getId());
                        depotItemMapperEx.updateList(depotItems);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newEntity = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newEntity != null) {
                    depotHeadMapper.insertSelective(newEntity);
                    List<DepotItem> depotItems = deliveryDepotMap.get(newEntity.getId());
                    depotItemMapperEx.insertList(depotItems);
                }
            }
            //仓库
            DepotExample depotExample = new DepotExample();
            depotExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
            List<Depot> oldDepots = depotMapper.selectByExample(depotExample);
            List<Depot> newDepots = JSONObject.parseArray(newJsonObject.getJSONArray("depots").toJSONString(), Depot.class);
            for (Depot newDepot : newDepots) {
                newDepot.setTenantId(tenantId);
                for (Depot oldDepot : oldDepots) {
                    if (newDepot.getId().equals(oldDepot.getId())) {
                        depotMapperEx.updateByPrimaryKeySelectiveEx(newDepot);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newDepot = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newDepot != null) {
                    depotMapperEx.insertSelectiveEx(newDepot);
                }
            }
            List<User> oldUsers = userMapper.selectByExample(new UserExample());
            List<User> newUsers = JSONObject.parseArray(newJsonObject.getJSONArray("users").toJSONString(), User.class);
            for (User newEntity : newUsers) {
                newEntity.setTenantId(null);
                for (User oldEntity : oldUsers) {
                    if (newEntity.getId().equals(oldEntity.getId())) {
//                        userMapper.updateByPrimaryKeySelective(newEntity);
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newEntity = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newEntity != null) {
                    userMapper.insertSelective(newEntity);
                }
            }
        } catch (Exception e) {
            JshException.writeFail(logger, e, this.getLanCode());
        }
    }

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    public void synchronizationUpAllocation(JSONObject newJsonObject) {
        try {
            Map<String, List<Attachment>> attachmentMap = JSONObject.parseObject(newJsonObject.getJSONObject("attachmentMap").toJSONString())
                    .entrySet().stream()
                    .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), Attachment.class)));
            //要货申请
            DepotHeadExample applyExample = new DepotHeadExample();
            applyExample.createCriteria().andSubTypeEqualTo("要货申请").andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
            List<DepotHead> oldApplyDepotHead = depotHeadMapper.selectByExample(applyExample);
            List<DepotHead> newApplyDepotHead = JSONObject.parseArray(newJsonObject.getJSONArray("applyDepotHead").toJSONString(), DepotHead.class);
            Map<String, List<DepotItem>> applyDepotMap = JSONObject.parseObject(newJsonObject.getJSONObject("applyDepotMap").toJSONString())
                    .entrySet().stream()
                    .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), DepotItem.class)));

            for (DepotHead newEntity : newApplyDepotHead) {
                newEntity.setUploadFlag("0");
                //                newEntity.setTenantId(tenantId);
                newEntity.setTenantId(null);
                for (DepotHead oldEntity : oldApplyDepotHead) {
                    if (newEntity.getId().equals(oldEntity.getId())) {
                        depotHeadMapper.updateByPrimaryKeySelective(newEntity);
                        List<DepotItem> newDepotItems = applyDepotMap.get(newEntity.getId());
                        if (newDepotItems != null && newDepotItems.size() > 0) {
                            List<DepotItem> oldDepotItems = synchronizationTaskMapperEx.getItemListByHeaderId(newEntity.getId());
                            Set<String> applySets = Sets.newHashSet();
                            oldDepotItems.forEach(existsVO -> {
                                applySets.add(existsVO.getId());
                            });
                            if (newDepotItems.size() > 0) {
                                for (DepotItem depotItem : newDepotItems) {
                                    depotItem.setTenantId(tenantId);
                                    if (applySets.contains(depotItem.getId())) {
                                        applySets.remove(depotItem.getId());
                                        synchronizationTaskMapperEx.updateDepotItemByPrimaryKeySelective(depotItem);
                                    }else {
                                        synchronizationTaskMapperEx.insertDepotItemSelective(depotItem);
                                    }
                                }
                            }
//                            depotItemMapperEx.updateList(depotItems);
                        }
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                        if (attachments.size() > 0) {
                            attachmentMapperEx.updateList(attachments);
                        }
                        newEntity = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newEntity != null) {
                    depotHeadMapper.insertSelective(newEntity);
                    List<DepotItem> depotItems = applyDepotMap.get(newEntity.getId());
                    depotItemMapperEx.insertList(depotItems);
                    List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                    if (attachments.size() > 0) {
                        attachmentMapperEx.insertList(attachments);
                    }
                }
            }
            DepotHeadExample deliveryExample = new DepotHeadExample();
            deliveryExample.createCriteria().andSubTypeEqualTo("配送").andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
            List<DepotHead> oldDeliveryDepotHead = depotHeadMapper.selectByExample(deliveryExample);
            List<DepotHead> newDeliveryDepotHead = JSONObject.parseArray(newJsonObject.getJSONArray("deliveryDepotHead").toJSONString(), DepotHead.class);
            Map<String, List<DepotItem>> deliveryDepotMap = JSONObject.parseObject(newJsonObject.getJSONObject("deliveryDepotMap").toJSONString())
                    .entrySet().stream()
                    .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), DepotItem.class)));

            for (DepotHead newEntity : newDeliveryDepotHead) {
                newEntity.setUploadFlag("0");
                //                newEntity.setTenantId(tenantId);
                newEntity.setTenantId(null);
                for (DepotHead oldEntity : oldDeliveryDepotHead) {
                    if (newEntity.getId().equals(oldEntity.getId())) {
                        depotHeadMapper.updateByPrimaryKeySelective(newEntity);
                        List<DepotItem> newDepotItems = deliveryDepotMap.get(newEntity.getId());
                        if (newDepotItems != null && newDepotItems.size() > 0) {
                            List<DepotItem> oldDepotItems = synchronizationTaskMapperEx.getItemListByHeaderId(newEntity.getId());
                            Set<String> applySets = Sets.newHashSet();
                            oldDepotItems.forEach(existsVO -> {
                                applySets.add(existsVO.getId());
                            });
                            if (newDepotItems.size() > 0) {
                                for (DepotItem depotItem : newDepotItems) {
                                    depotItem.setTenantId(tenantId);
                                    if (applySets.contains(depotItem.getId())) {
                                        applySets.remove(depotItem.getId());
                                        synchronizationTaskMapperEx.updateDepotItemByPrimaryKeySelective(depotItem);
                                    }else {
                                        synchronizationTaskMapperEx.insertDepotItemSelective(depotItem);
                                    }
                                }
                            }
//                            depotItemMapperEx.updateList(depotItems);
                        }
                        List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                        if (attachments.size() > 0) {
                            attachmentMapperEx.updateList(attachments);
                        }
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newEntity = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newEntity != null) {
                    depotHeadMapper.insertSelective(newEntity);
                    List<DepotItem> depotItems = deliveryDepotMap.get(newEntity.getId());
                    depotItemMapperEx.insertList(depotItems);
                    List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                    if (attachments.size() > 0) {
                        attachmentMapperEx.insertList(attachments);
                    }
                }
            }
            DepotHeadExample acceptanceExample = new DepotHeadExample();
            acceptanceExample.createCriteria().andSubTypeEqualTo("验收").andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
            List<DepotHead> oldAcceptanceDepotHead = depotHeadMapper.selectByExample(acceptanceExample);
            List<DepotHead> newAcceptanceDepotHead = JSONObject.parseArray(newJsonObject.getJSONArray("acceptanceDepotHead").toJSONString(), DepotHead.class);
            Map<String, List<DepotItem>> acceptanceDepotMap = JSONObject.parseObject(newJsonObject.getJSONObject("acceptanceDepotMap").toJSONString())
                    .entrySet().stream()
                    .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), DepotItem.class)));

            for (DepotHead newEntity : newAcceptanceDepotHead) {
                newEntity.setUploadFlag("0");
                //                newEntity.setTenantId(tenantId);
                newEntity.setTenantId(null);
                for (DepotHead oldEntity : oldAcceptanceDepotHead) {
                    if (newEntity.getId().equals(oldEntity.getId())) {
                        depotHeadMapper.updateByPrimaryKeySelective(newEntity);
                        List<DepotItem> newDepotItems = acceptanceDepotMap.get(newEntity.getId());
                        if (newDepotItems != null && newDepotItems.size() > 0) {
                            List<DepotItem> oldDepotItems = synchronizationTaskMapperEx.getItemListByHeaderId(newEntity.getId());
                            Set<String> applySets = Sets.newHashSet();
                            oldDepotItems.forEach(existsVO -> {
                                applySets.add(existsVO.getId());
                            });
                            if (newDepotItems.size() > 0) {
                                for (DepotItem depotItem : newDepotItems) {
                                    depotItem.setTenantId(tenantId);
                                    if (applySets.contains(depotItem.getId())) {
                                        applySets.remove(depotItem.getId());
                                        synchronizationTaskMapperEx.updateDepotItemByPrimaryKeySelective(depotItem);
                                    }else {
                                        synchronizationTaskMapperEx.insertDepotItemSelective(depotItem);
                                    }
                                }
                            }
//                            depotItemMapperEx.updateList(depotItems);
                        }
                        List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                        if (attachments.size() > 0) {
                            attachmentMapperEx.updateList(attachments);
                        }
                        //新旧数据比对并操作后，将新数据从List中“移除”
                        newEntity = null;
                        break;
                    }
                }
                //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                //没被置null说明这条新数据是新增的，需要调用接口落盘
                if (newEntity != null) {
                    depotHeadMapper.insertSelective(newEntity);
                    List<DepotItem> depotItems = acceptanceDepotMap.get(newEntity.getId());
                    depotItemMapperEx.insertList(depotItems);
                    List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                    if (attachments.size() > 0) {
                        attachmentMapperEx.insertList(attachments);
                    }
                }
            }

            //采购订单
            JSONArray purchaseDepotHead = newJsonObject.getJSONArray("purchaseDepotHead");
            if (null != purchaseDepotHead && purchaseDepotHead.size() > 0) {
                List<DepotHead> oldPurchaseDepotHead = synchronizationTaskMapperEx.selectECSDepotHeadByType("采购订单");
                List<DepotHead> newPurchaseDepotHead = JSONObject.parseArray(newJsonObject.getJSONArray("purchaseDepotHead").toJSONString(), DepotHead.class);
                Map<String, List<DepotItem>> purchaseDepotMap = JSONObject.parseObject(newJsonObject.getJSONObject("purchaseDepotMap").toJSONString())
                        .entrySet().stream()
                        .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), DepotItem.class)));

                for (DepotHead newEntity : newPurchaseDepotHead) {
                    newEntity.setUploadFlag("1");
                    newEntity.setTenantId(newEntity.getCustom5());
                    for (DepotHead oldEntity : oldPurchaseDepotHead) {
                        if (newEntity.getId().equals(oldEntity.getId())) {
                            synchronizationTaskMapperEx.updateDepotHeadByPrimaryKeySelective(newEntity);
                            List<DepotItem> depotItems = purchaseDepotMap.get(newEntity.getId());
                            if (depotItems != null && depotItems.size() > 0) {
                                synchronizationTaskMapperEx.updateDepotItemList(depotItems,newEntity.getCustom5());
                            }
                            List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                            if (attachments.size() > 0) {
                                synchronizationTaskMapperEx.updateAttachmentList(attachments,newEntity.getCustom5());
                            }
                            //新旧数据比对并操作后，将新数据从List中“移除”
                            newEntity = null;
                            break;
                        }
                    }
                    //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                    //没被置null说明这条新数据是新增的，需要调用接口落盘
                    if (newEntity != null) {
                        synchronizationTaskMapperEx.insertDepotHeadSelective(newEntity);
                        List<DepotItem> depotItems = purchaseDepotMap.get(newEntity.getId());
                        synchronizationTaskMapperEx.insertDepotItemList(depotItems,newEntity.getCustom5());
                        List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                        if (attachments.size() > 0) {
                            synchronizationTaskMapperEx.insertAttachmentList(attachments,newEntity.getCustom5());
                        }
                    }
                }
//                //报价单
//                JSONArray quotationDepotHead = newJsonObject.getJSONArray("quotationDepotHead");
//                if (null != quotationDepotHead && quotationDepotHead.size() > 0) {
//                    List<DepotHead> oldQuotationDepotHead = synchronizationTaskMapperEx.selectECSDepotHeadByType("厂家报价");
//                    List<DepotHead> newQuotationDepotHead = JSONObject.parseArray(newJsonObject.getJSONArray("quotationDepotHead").toJSONString(), DepotHead.class);
//                    Map<String, List<DepotItem>> quotationDepotMap = JSONObject.parseObject(newJsonObject.getJSONObject("quotationDepotMap").toJSONString())
//                            .entrySet().stream()
//                            .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), DepotItem.class)));
//
//                    for (DepotHead newEntity : newQuotationDepotHead) {
//                        newEntity.setUploadFlag("1");
//                        newEntity.setTenantId(newEntity.getCustom5());
//                        for (DepotHead oldEntity : oldQuotationDepotHead) {
//                            if (newEntity.getId().equals(oldEntity.getId())) {
//                                synchronizationTaskMapperEx.updateDepotHeadByPrimaryKeySelective(newEntity);
//                                List<DepotItem> depotItems = quotationDepotMap.get(newEntity.getId());
//                                if (depotItems != null && depotItems.size() > 0) {
//                                    synchronizationTaskMapperEx.updateDepotItemList(depotItems,newEntity.getCustom5());
//                                }
//                                List<Attachment> attachments = attachmentMap.get(newEntity.getId());
//                                if (attachments.size() > 0) {
//                                    synchronizationTaskMapperEx.updateAttachmentList(attachments,newEntity.getCustom5());
//                                }
//                                //新旧数据比对并操作后，将新数据从List中“移除”
//                                newEntity = null;
//                                break;
//                            }
//                        }
//                        //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                        //没被置null说明这条新数据是新增的，需要调用接口落盘
//                        if (newEntity != null) {
//                            synchronizationTaskMapperEx.insertDepotHeadSelective(newEntity);
//                            List<DepotItem> depotItems = quotationDepotMap.get(newEntity.getId());
//                            synchronizationTaskMapperEx.insertDepotItemList(depotItems,newEntity.getCustom5());
//                            List<Attachment> attachments = attachmentMap.get(newEntity.getId());
//                            if (attachments.size() > 0) {
//                                synchronizationTaskMapperEx.insertAttachmentList(attachments,newEntity.getCustom5());
//                            }
//                        }
//                    }
//                }
                //采购入库
                JSONArray stockInDepotHead = newJsonObject.getJSONArray("stockInDepotHead");
                if (null != stockInDepotHead && stockInDepotHead.size() > 0) {
                    List<DepotHead> oldStockInDepotHead = synchronizationTaskMapperEx.selectECSDepotHeadByType("采购");
                    List<DepotHead> newStockDepotHead = JSONObject.parseArray(newJsonObject.getJSONArray("stockInDepotHead").toJSONString(), DepotHead.class);
                    Map<String, List<DepotItem>> stockInDepotMap = JSONObject.parseObject(newJsonObject.getJSONObject("stockInDepotMap").toJSONString())
                            .entrySet().stream()
                            .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), DepotItem.class)));

                    for (DepotHead newEntity : newStockDepotHead) {
                        newEntity.setUploadFlag("1");
                        newEntity.setTenantId(newEntity.getCustom5());
                        for (DepotHead oldEntity : oldStockInDepotHead) {
                            if (newEntity.getId().equals(oldEntity.getId())) {
                                synchronizationTaskMapperEx.updateDepotHeadByPrimaryKeySelective(newEntity);
                                List<DepotItem> depotItems = stockInDepotMap.get(newEntity.getId());
                                if (depotItems != null && depotItems.size() > 0) {
                                    synchronizationTaskMapperEx.updateDepotItemList(depotItems, newEntity.getCustom5());
                                }
                                List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                                if (attachments.size() > 0) {
                                    synchronizationTaskMapperEx.updateAttachmentList(attachments, newEntity.getCustom5());
                                }
                                //新旧数据比对并操作后，将新数据从List中“移除”
                                newEntity = null;
                                break;
                            }
                        }
                        //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                        //没被置null说明这条新数据是新增的，需要调用接口落盘
                        if (newEntity != null) {
                            synchronizationTaskMapperEx.insertDepotHeadSelective(newEntity);
                            List<DepotItem> depotItems = stockInDepotMap.get(newEntity.getId());
                            synchronizationTaskMapperEx.insertDepotItemList(depotItems, newEntity.getCustom5());
                            List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                            if (attachments.size() > 0) {
                                synchronizationTaskMapperEx.insertAttachmentList(attachments, newEntity.getCustom5());
                            }
                        }
                    }
                }
            }

            JSONArray purchaseReturnList = newJsonObject.getJSONArray("purchaseReturnList");
            if (null != purchaseReturnList && purchaseReturnList.size() > 0) {
                List<DepotHead> oldPurchaseReturnList = synchronizationTaskMapperEx.selectECSDepotHeadByType("采购退货");
                List<DepotHead> newPurchaseReturnList = JSONObject.parseArray(newJsonObject.getJSONArray("purchaseReturnList").toJSONString(), DepotHead.class);
                Map<String, List<DepotItem>> purchaseReturnDepotMap = JSONObject.parseObject(newJsonObject.getJSONObject("purchaseReturnDepotMap").toJSONString())
                        .entrySet().stream()
                        .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), DepotItem.class)));

                for (DepotHead newEntity : newPurchaseReturnList) {
                    newEntity.setUploadFlag("1");
                    newEntity.setTenantId(newEntity.getCustom5());
                    for (DepotHead oldEntity : oldPurchaseReturnList) {
                        if (newEntity.getId().equals(oldEntity.getId())) {
                            synchronizationTaskMapperEx.updateDepotHeadByPrimaryKeySelective(newEntity);
                            List<DepotItem> depotItems = purchaseReturnDepotMap.get(newEntity.getId());
                            if (depotItems != null && depotItems.size() > 0) {
                                synchronizationTaskMapperEx.updateDepotItemList(depotItems, newEntity.getCustom5());
                            }
                            List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                            if (attachments.size() > 0) {
                                synchronizationTaskMapperEx.updateAttachmentList(attachments, newEntity.getCustom5());
                            }
                            //新旧数据比对并操作后，将新数据从List中“移除”
                            newEntity = null;
                            break;
                        }
                    }
                    //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                    //没被置null说明这条新数据是新增的，需要调用接口落盘
                    if (newEntity != null) {
                        synchronizationTaskMapperEx.insertDepotHeadSelective(newEntity);
                        List<DepotItem> depotItems = purchaseReturnDepotMap.get(newEntity.getId());
                        synchronizationTaskMapperEx.insertDepotItemList(depotItems, newEntity.getCustom5());
                        List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                        if (attachments.size() > 0) {
                            synchronizationTaskMapperEx.insertAttachmentList(attachments, newEntity.getCustom5());
                        }
                    }
                }
            }
        } catch (Exception e) {
            JshException.writeFail(logger, e, "zh");
        }
    }

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    public void synchronizationBasicDataTask(JSONObject newJsonObject) throws Exception {
//        //租户
//        List<Tenant> newTenant = JSONObject.parseArray(newJsonObject.getJSONArray("tenantList").toJSONString(), Tenant.class);
//        List<Tenant> oldTenant = synchronizationTaskMapperEx.selectTenant(tenantId);
//        for (Tenant newData : newTenant) {
//            newData.setTenantId(tenantId);
//            for (Tenant oldMaterial : oldTenant) {
//                if (newData.getId().equals(oldMaterial.getId())) {
//                    synchronizationTaskMapperEx.updateTenantTime(newData);
//                    //新旧数据比对并操作后，将新数据从List中“移除”
//                    newData = null;
//                    break;
//                }
//            }
//            //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//            //没被置null说明这条新数据是新增的，需要调用接口落盘
//            if (newData != null) {
//                synchronizationTaskMapperEx.insertTenant(newData);
//            }
//        }
//        //用户
        //用户
        if (null != newJsonObject && newJsonObject.size() > 0) {
            JSONArray userList = newJsonObject.getJSONArray("userList");
            if (null != userList && userList.size() > 0) {
                List<User> newUser = JSONObject.parseArray(newJsonObject.getJSONArray("userList").toJSONString(), User.class);
                List<User> oldUser = synchronizationTaskMapperEx.selectUserNotTenantId();
                for (User newData : newUser) {
                    for (User oldMaterial : oldUser) {
                        if (newData.getId().equals(oldMaterial.getId())) {
                            if (!newData.getId().equals("120")) {
                                synchronizationTaskMapperEx.updateUserTime(newData);
                            }
                            //新旧数据比对并操作后，将新数据从List中“移除”
                            newData = null;
                            break;
                        }
                    }
                    //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                    //没被置null说明这条新数据是新增的，需要调用接口落盘
                    if (newData != null) {
                        if (!newData.getId().equals("120")) {
                            synchronizationTaskMapperEx.insertUser(newData);
                        }
                    }
                }
            }
        }
        //供应商
        if (null != newJsonObject && newJsonObject.size() > 0) {
            JSONArray suppliers = newJsonObject.getJSONArray("suppliers");
            List<Supplier> oldSuppliers = synchronizationTaskMapperEx.selectOldSupplier(tenantId, "供应商");
            if (null != suppliers && suppliers.size() > 0) {
                List<Supplier> newSuppliers = JSONObject.parseArray(newJsonObject.getJSONArray("suppliers").toJSONString(), Supplier.class);
                for (Supplier newEntity : newSuppliers) {
                    newEntity.setTenantId(tenantId);
                    for (Supplier oldEntity : oldSuppliers) {
                        if (newEntity.getId().equals(oldEntity.getId())) {
//                            if (newEntity.getUpdateTime() != null) {
//                                if (oldEntity.getUpdateTime() != null) {
//                                    long newTime = newEntity.getUpdateTime().getTime();
//                                    long oldTime = newEntity.getUpdateTime().getTime();
//                                    if (newTime > oldTime) {
//                                        synchronizationTaskMapperEx.updateSupplierEntity(newEntity);
//                                    }
//                                } else {
//                                    synchronizationTaskMapperEx.updateSupplierEntity(newEntity);
//                                }
//                            }
                            synchronizationTaskMapperEx.updateSupplierEntity(newEntity);
                            //新旧数据比对并操作后，将新数据从List中“移除”
                            newEntity = null;
                            oldSuppliers.remove(oldEntity);
                            break;
                        }
                    }
                    //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                    //没被置null说明这条新数据是新增的，需要调用接口落盘
                    if (newEntity != null) {
                        synchronizationTaskMapperEx.insertSupplier(newEntity);
                    }
                }
            } else {
                if (oldSuppliers != null && oldSuppliers.size() > 0) {
                    for (Supplier oldData : oldSuppliers) {
                        if (oldData != null) {
                            synchronizationTaskMapperEx.updateSupplierEnabled(oldData.getId());
                        }
                    }
                }
            }
        }
//        //用户类型
//        List<UserCategory> newUserCategory = JSONObject.parseArray(newJsonObject.getJSONArray("userCategoryList").toJSONString(), UserCategory.class);
//        List<UserCategory> oldUserCategory = synchronizationTaskMapperEx.selectUserCategory(tenantId);
//        for (UserCategory newData : newUserCategory) {
//            newData.setTenantId(tenantId);
//            for (UserCategory oldMaterial : oldUserCategory) {
//                if (newData.getId().equals(oldMaterial.getId())) {
//                    synchronizationTaskMapperEx.updateUserCategoryTime(newData);
//                    //新旧数据比对并操作后，将新数据从List中“移除”
//                    newData = null;
//                    break;
//                }
//            }
//            //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//            //没被置null说明这条新数据是新增的，需要调用接口落盘
//            if (newData != null) {
//                synchronizationTaskMapperEx.insertUserCategory(newData);
//            }
//        }
//        //用户/角色/模块关系表
//        List<UserBusiness> newUserBusiness = JSONObject.parseArray(newJsonObject.getJSONArray("userBusinessList").toJSONString(), UserBusiness.class);
//        List<UserBusiness> oldUserBusiness = synchronizationTaskMapperEx.selectUserBusiness(tenantId);
//        for (UserBusiness newData : newUserBusiness) {
//            newData.setTenantId(tenantId);
//            for (UserBusiness oldMaterial : oldUserBusiness) {
//                if (newData.getId().equals(oldMaterial.getId())) {
//                    synchronizationTaskMapperEx.updateUserBusinessTime(newData);
//                    //新旧数据比对并操作后，将新数据从List中“移除”
//                    newData = null;
//                    break;
//                }
//            }
//            //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//            //没被置null说明这条新数据是新增的，需要调用接口落盘
//            if (newData != null) {
//                synchronizationTaskMapperEx.insertUserBusiness(newData);
//            }
//        }
//        //角色
//        List<Role> newRole = JSONObject.parseArray(newJsonObject.getJSONArray("roleList").toJSONString(), Role.class);
//        List<Role> oldRole = synchronizationTaskMapperEx.selectRole(tenantId);
//        for (Role newData : newRole) {
//            newData.setTenantId(tenantId);
//            for (Role oldMaterial : oldRole) {
//                if (newData.getId().equals(oldMaterial.getId())) {
//                    synchronizationTaskMapperEx.updateRoleTime(newData);
//                    //新旧数据比对并操作后，将新数据从List中“移除”
//                    newData = null;
//                    break;
//                }
//            }
//            //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//            //没被置null说明这条新数据是新增的，需要调用接口落盘
//            if (newData != null) {
//                synchronizationTaskMapperEx.insertRole(newData);
//            }
//        }
        //经手人表
//        List<Person> newPerson = JSONObject.parseArray(newJsonObject.getJSONArray("personList").toJSONString(), Person.class);
//        List<Person> oldPerson = synchronizationTaskMapperEx.selectPerson(tenantId);
//        for (Person newData : newPerson) {
//            newData.setTenantId(tenantId);
//            for (Person oldMaterial : oldPerson) {
//                if (newData.getId().equals(oldMaterial.getId())) {
//                    synchronizationTaskMapperEx.updatePersonTime(newData);
//                    //新旧数据比对并操作后，将新数据从List中“移除”
//                    newData = null;
//                    break;
//                }
//            }
//            //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//            //没被置null说明这条新数据是新增的，需要调用接口落盘
//            if (newData != null) {
//                synchronizationTaskMapperEx.insertPerson(newData);
//            }
//        }
//        //机构表
//        List<Organization> newOrganization = JSONObject.parseArray(newJsonObject.getJSONArray("organizationList").toJSONString(), Organization.class);
//        List<Organization> oldOrganization = synchronizationTaskMapperEx.selectOrganization(tenantId);
//        for (Organization newData : newOrganization) {
//            newData.setTenantId(tenantId);
//            for (Organization oldMaterial : oldOrganization) {
//                if (newData.getId().equals(oldMaterial.getId())) {
//                    synchronizationTaskMapperEx.updateOrganizationTime(newData);
//                    //新旧数据比对并操作后，将新数据从List中“移除”
//                    newData = null;
//                    break;
//                }
//            }
//            //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//            //没被置null说明这条新数据是新增的，需要调用接口落盘
//            if (newData != null) {
//                synchronizationTaskMapperEx.insertOrganization(newData);
//            }
//        }
//        //机构用户关系表
//        List<OrgaUserRel> newOrgaUserRel = JSONObject.parseArray(newJsonObject.getJSONArray("orgaUserRelList").toJSONString(), OrgaUserRel.class);
//        List<OrgaUserRel> oldOrgaUserRel = synchronizationTaskMapperEx.selectOrgaUserRel(tenantId);
//        for (OrgaUserRel newData : newOrgaUserRel) {
//            newData.setTenantId(tenantId);
//            for (OrgaUserRel oldMaterial : oldOrgaUserRel) {
//                if (newData.getId().equals(oldMaterial.getId())) {
//                    synchronizationTaskMapperEx.updateOrgaUserRelTime(newData);
//                    //新旧数据比对并操作后，将新数据从List中“移除”
//                    newData = null;
//                    break;
//                }
//            }
//            //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//            //没被置null说明这条新数据是新增的，需要调用接口落盘
//            if (newData != null) {
//                synchronizationTaskMapperEx.insertOrgaUserRel(newData);
//            }
//        }
        //促销主表
        if (null != newJsonObject && newJsonObject.size() > 0) {
            JSONArray promotionHeadList = newJsonObject.getJSONArray("promotionHeadList");
            List<PromotionHead> oldPromotionHead = synchronizationTaskMapperEx.selectPromotionHead(tenantId);
            if (null != promotionHeadList && promotionHeadList.size() > 0) {
                List<PromotionHead> newPromotionHead = JSONObject.parseArray(newJsonObject.getJSONArray("promotionHeadList").toJSONString(), PromotionHead.class);
                Map<String, List<PromotionItem>> promotionItemMap = JSONObject.parseObject(newJsonObject.getJSONObject("promotionItemMap").toJSONString())
                        .entrySet().stream()
                        .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), PromotionItem.class)));

                Map<String, List<PromotionGift>> promotionGiftMap = JSONObject.parseObject(newJsonObject.getJSONObject("promotionGiftMap").toJSONString())
                        .entrySet().stream()
                        .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), PromotionGift.class)));
                for (PromotionHead newData : newPromotionHead) {
                    newData.setTenantId(tenantId);
                    for (PromotionHead oldData : oldPromotionHead) {
                        if (newData.getId().equals(oldData.getId())) {
                            synchronizationTaskMapperEx.updatePromotionHeadTime(newData);
                            List<PromotionItem> promotionItems = promotionItemMap.get(newData.getId());
                            if (null != promotionItems && promotionItems.size() > 0) {
                                synchronizationTaskMapperEx.updatePromotionItemTime(promotionItems, tenantId);
                            }
                            List<PromotionGift> promotionGifts = promotionGiftMap.get(newData.getId());
                            if (null != promotionGifts && promotionGifts.size() > 0) {
                                synchronizationTaskMapperEx.updatePromotionGiftTime(promotionGifts, tenantId);
                            }
                            //新旧数据比对并操作后，将新数据从List中“移除”
                            newData = null;
                            oldPromotionHead.remove(oldData);
                            break;
                        }
                    }
                    //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                    //没被置null说明这条新数据是新增的，需要调用接口落盘
                    if (newData != null) {
                        synchronizationTaskMapperEx.insertPromotionHead(newData);
                        List<PromotionItem> promotionItems = promotionItemMap.get(newData.getId());
                        if (null != promotionItems && promotionItems.size() > 0) {
                            synchronizationTaskMapperEx.insertPromotionItem(promotionItems, tenantId);
                        }
                        List<PromotionGift> promotionGifts = promotionGiftMap.get(newData.getId());
                        if (null != promotionGifts && promotionGifts.size() > 0) {
                            synchronizationTaskMapperEx.insertPromotionGift(promotionGifts, tenantId);
                        }
                    }
                }
            } else {
                if (oldPromotionHead != null && oldPromotionHead.size() > 0) {
                    for (PromotionHead oldData : oldPromotionHead) {
                        if (oldData != null) {
                            synchronizationTaskMapperEx.deletePromotionHead(oldData.getId());
                        }
                    }
                }
            }
        }
        //返利
        if (null != newJsonObject && newJsonObject.size() > 0) {
            JSONArray rebates = newJsonObject.getJSONArray("rebates");
            List<Rebate> oldRebates = synchronizationTaskMapperEx.selectRebate(tenantId);
            if (null != rebates && rebates.size() > 0) {
                List<Rebate> newRebates = JSONObject.parseArray(newJsonObject.getJSONArray("rebates").toJSONString(), Rebate.class);
                Map<String, List<RebateItem>> rebateItemMap = JSONObject.parseObject(newJsonObject.getJSONObject("rebateItemMap").toJSONString())
                        .entrySet().stream()
                        .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), RebateItem.class)));

                for (Rebate newData : newRebates) {
                    newData.setTenantId(tenantId);
                    for (Rebate oldData : oldRebates) {
                        if (newData.getId().equals(oldData.getId())) {
                            synchronizationTaskMapperEx.updateRebateByPrimaryKeySelective(newData);
                            List<RebateItem> rebateItems = rebateItemMap.get(newData.getId());
                            if (null != rebateItems && rebateItems.size() > 0) {
                                synchronizationTaskMapperEx.updateRebateItemTime(rebateItems, tenantId);
                            }
                            //新旧数据比对并操作后，将新数据从List中“移除”
                            newData = null;
                            oldRebates.remove(oldData);
                            break;
                        }
                    }
                    //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                    //没被置null说明这条新数据是新增的，需要调用接口落盘
                    if (newData != null) {
                        synchronizationTaskMapperEx.insertRebateSelective(newData);
                        List<RebateItem> rebateItems = rebateItemMap.get(newData.getId());
                        if (null != rebateItems && rebateItems.size() > 0) {
                            synchronizationTaskMapperEx.insertRebateItemTime(rebateItems, tenantId);
                        }
                    }
                }
            } else {
                if (oldRebates != null && oldRebates.size() > 0) {
                    for (Rebate oldData : oldRebates) {
                        if (oldData != null) {
                            synchronizationTaskMapperEx.deleteRebate(oldData.getId());
                        }
                    }
                }
            }
        }

        //商品
        if (null != newJsonObject && newJsonObject.size() > 0) {
            JSONArray materials = newJsonObject.getJSONArray("materials");
            List<Material> oldMaterials = synchronizationTaskMapperEx.selectMaterial(tenantId);
            if (null != materials && materials.size() > 0) {
                List<Material> newMaterials = JSONObject.parseArray(newJsonObject.getJSONArray("materials").toJSONString(), Material.class);

                Map<String, Unit> unitMap = JSONObject.parseObject(newJsonObject.getJSONObject("unitMap").toJSONString(), new TypeReference<Map<String, Unit>>() {
                });

                Map<String, List<Attachment>> attachmentMap = JSONObject.parseObject(newJsonObject.getJSONObject("attachmentMap").toJSONString())
                        .entrySet().stream()
                        .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), Attachment.class)));

                Map<String, List<MaterialExtend>> materialExtendMap = JSONObject.parseObject(newJsonObject.getJSONObject("materialExtendMap").toJSONString())
                        .entrySet().stream()
                        .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), MaterialExtend.class)));
                for (Material newEntity : newMaterials) {
                    newEntity.setTenantId(tenantId);
                    for (Material oldEntity : oldMaterials) {
                        if (newEntity.getId().equals(oldEntity.getId())) {
//                            if (newEntity.getUpdateTime() != null) {
//                                if (oldEntity.getUpdateTime() != null) {
//                                    long newTime = newEntity.getUpdateTime().getTime();
//                                    long oldTime = oldEntity.getUpdateTime().getTime();
//                                    if (newTime > oldTime) {
//                                        synchronizationTaskMapperEx.updateMaterialByPrimaryKeySelective(newEntity);
//                                        List<Attachment> attachments = attachmentMap.get(newEntity.getId());
//                                        if (null != attachments && attachments.size() > 0) {
//                                            synchronizationTaskMapperEx.updateAttachmentList(attachments, tenantId);
//                                        }
//                                        List<MaterialExtend> materialExtends = materialExtendMap.get(newEntity.getId());
//                                        if (null != materialExtends && materialExtends.size() > 0) {
//                                            synchronizationTaskMapperEx.updateMaterialExtendList(materialExtends, tenantId);
//                                        }
//                                        Unit unit = unitMap.get(newEntity.getId());
//                                        unit.setTenantId(tenantId);
//                                        synchronizationTaskMapperEx.updateUnitTime(unit);
//                                    }
//                                }else {
//                                    synchronizationTaskMapperEx.updateMaterialByPrimaryKeySelective(newEntity);
//                                    List<Attachment> attachments = attachmentMap.get(newEntity.getId());
//                                    if (null != attachments && attachments.size() > 0) {
//                                        synchronizationTaskMapperEx.updateAttachmentList(attachments, tenantId);
//                                    }
//                                    List<MaterialExtend> materialExtends = materialExtendMap.get(newEntity.getId());
//                                    if (null != materialExtends && materialExtends.size() > 0) {
//                                        synchronizationTaskMapperEx.updateMaterialExtendList(materialExtends, tenantId);
//                                    }
//                                    Unit unit = unitMap.get(newEntity.getId());
//                                    unit.setTenantId(tenantId);
//                                    synchronizationTaskMapperEx.updateUnitTime(unit);
//                                }
//                            }
                            synchronizationTaskMapperEx.updateMaterialByPrimaryKeySelective(newEntity);
                            List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                            if (null != attachments && attachments.size() > 0) {
                                synchronizationTaskMapperEx.updateAttachmentList(attachments, tenantId);
                            }
                            List<MaterialExtend> materialExtends = materialExtendMap.get(newEntity.getId());
                            if (null != materialExtends && materialExtends.size() > 0) {
                                synchronizationTaskMapperEx.updateMaterialExtendList(materialExtends, tenantId);
                            }
                            Unit unit = unitMap.get(newEntity.getId());
                            unit.setTenantId(tenantId);
                            synchronizationTaskMapperEx.updateUnitTime(unit);
                            //新旧数据比对并操作后，将这个数据从List中“移除”
                            newEntity = null;
                            oldMaterials.remove(oldEntity);
                            break;
                        }
                    }
                    //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                    //没被置null说明这条新数据是新增的，需要调用接口落盘
                    if (newEntity != null) {
                        synchronizationTaskMapperEx.insertMaterialSelective(newEntity);
                        List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                        if (null != attachments && attachments.size() > 0) {
                            synchronizationTaskMapperEx.insertAttachmentList(attachments, tenantId);
                        }
                        List<MaterialExtend> materialExtends = materialExtendMap.get(newEntity.getId());
                        if (null != materialExtends && materialExtends.size() > 0) {
                            synchronizationTaskMapperEx.insertMaterialExtendList(materialExtends, tenantId);
                        }
                        Unit unit = unitMap.get(newEntity.getId());
                        unit.setTenantId(tenantId);
                        synchronizationTaskMapperEx.insertUnit(unit);
                    }
                }
            } else {
                if (oldMaterials != null && oldMaterials.size() > 0) {
                    List<String> idList = oldMaterials.stream().map(Material::getId).collect(Collectors.toList());
                    synchronizationTaskMapperEx.updateMaterialEnabled(idList);
//                    for (Material oldData : oldMaterials) {
//                        if (oldData != null) {
//                            synchronizationTaskMapperEx.updateMaterialEnabled(oldData.getId());
//                        }
//                    }
                }
            }
        }
        //商品分类
        if (null != newJsonObject && newJsonObject.size() > 0) {
            JSONArray materialCategories = newJsonObject.getJSONArray("materialCategories");
            if (null != materialCategories && materialCategories.size() > 0) {
                //商品类型
                List<MaterialCategory> oldMaterialCategories = synchronizationTaskMapperEx.selectMaterialCategory(tenantId);
                List<MaterialCategory> newMaterialCategories = JSONObject.parseArray(newJsonObject.getJSONArray("materialCategories").toJSONString(), MaterialCategory.class);
                for (MaterialCategory newEntity : newMaterialCategories) {
                    newEntity.setTenantId(tenantId);
                    for (MaterialCategory oldEntity : oldMaterialCategories) {
                        if (newEntity.getId().equals(oldEntity.getId())) {
//                            if (newEntity.getUpdateTime() != null) {
//                                if (oldEntity.getUpdateTime() != null) {
//                                    long newTime = newEntity.getUpdateTime().getTime();
//                                    long oldTime = newEntity.getUpdateTime().getTime();
//                                    if (newTime > oldTime) {
//                                        synchronizationTaskMapperEx.updateMaterialCategoryTime(newEntity);
//                                    }
//                                } else {
//                                    synchronizationTaskMapperEx.updateMaterialCategoryTime(newEntity);
//                                }
//                            }
                            synchronizationTaskMapperEx.updateMaterialCategoryTime(newEntity);
                            //新旧数据比对并操作后，将新数据从List中“移除”
                            newEntity = null;
                            break;
                        }
                    }
                    //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                    //没被置null说明这条新数据是新增的，需要调用接口落盘
                    if (newEntity != null) {
                        synchronizationTaskMapperEx.insertMaterialCategory(newEntity);
                    }
                }
            }
        }
        //仓库
        if (null != newJsonObject && newJsonObject.size() > 0) {
            JSONArray depotList = newJsonObject.getJSONArray("depotList");
            if (null != depotList && depotList.size() > 0) {
                List<Depot> newDepot = JSONObject.parseArray(depotList.toJSONString(), Depot.class);
                List<Depot> oldDepot = synchronizationTaskMapperEx.selectDepotTime();
                for (Depot newData : newDepot) {
                    for (Depot oldMaterial : oldDepot) {
                        if (newData.getId().equals(oldMaterial.getId())) {
                            if (!newData.getName().equals(oldMaterial.getName())) {
                                synchronizationTaskMapperEx.updateDepotTime(newData);
                            }
                            //新旧数据比对并操作后，将新数据从List中“移除”
                            newData = null;
                            break;
                        }
                    }
                    //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                    //没被置null说明这条新数据是新增的，需要调用接口落盘
                    if (newData != null) {
                        synchronizationTaskMapperEx.insertDepot(newData);
                    }
                }
            }
        }

    }

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    public void synchronizationBasicData(JSONObject newJsonObject, Boolean flag) throws Exception {
//        //租户
//        List<Tenant> newTenant = JSONObject.parseArray(newJsonObject.getJSONArray("tenantList").toJSONString(), Tenant.class);
//        List<Tenant> oldTenant = synchronizationTaskMapperEx.selectTenant(tenantId);
//        for (Tenant newData : newTenant) {
//            newData.setTenantId(tenantId);
//            for (Tenant oldMaterial : oldTenant) {
//                if (newData.getId().equals(oldMaterial.getId())) {
//                    synchronizationTaskMapperEx.updateTenantTime(newData);
//                    //新旧数据比对并操作后，将新数据从List中“移除”
//                    newData = null;
//                    break;
//                }
//            }
//            //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//            //没被置null说明这条新数据是新增的，需要调用接口落盘
//            if (newData != null) {
//                synchronizationTaskMapperEx.insertTenant(newData);
//            }
//        }
//        if (null != newJsonObject && newJsonObject.size() > 0) {
//            JSONArray accountHeads = newJsonObject.getJSONArray("accountHeads");
//            if (null != accountHeads && accountHeads.size() > 0) {
//                //财务单据表头
//                List<AccountHead> oldAccountHeads = synchronizationTaskMapperEx.selectAccountHead(accountHeadExample);
//                List<AccountHead> newAccountHeads = JSONObject.parseArray(newJsonObject.getJSONArray("accountHeads").toJSONString(), AccountHead.class);
//                for (AccountHead newAccountHead : newAccountHeads) {
//                    for (AccountHead oldAccountHead : oldAccountHeads) {
//                        if (newAccountHead.getId().equals(oldAccountHead.getId())) {
//                            accountHeadMapper.updateByPrimaryKeySelective(newAccountHead);
//                            //新旧数据比对并操作后，将新数据从List中“移除”
//                            newAccountHead = null;
//                            break;
//                        }
//                    }
//                    //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                    //没被置null说明这条新数据是新增的，需要调用接口落盘
//                    if (newAccountHead != null) {
//                        accountHeadMapper.insertSelective(newAccountHead);
//                    }
//                }
//
//                //财务单据表体
//                AccountItemExample accountItemExample = new AccountItemExample();
//                List<AccountItem> oldAccountItems = accountItemMapper.selectByExample(accountItemExample);
//                List<AccountItem> newAccountItems = JSONObject.parseArray(newJsonObject.getJSONArray("accountItems").toJSONString(), AccountItem.class);
//                for (AccountItem newAccountItem : newAccountItems) {
//                    for (AccountItem oldAccountItem : oldAccountItems) {
//                        if (newAccountItem.getId().equals(oldAccountItem.getId())) {
//                            accountItemMapper.updateByPrimaryKeySelective(newAccountItem);
//                            //新旧数据比对并操作后，将新数据从List中“移除”
//                            newAccountItem = null;
//                            break;
//                        }
//                    }
//                    //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                    //没被置null说明这条新数据是新增的，需要调用接口落盘
//                    if (newAccountItem != null) {
//                        accountItemMapper.insertSelective(newAccountItem);
//                    }
//                }
//            }
//        }
        //账户信息
        if (null != newJsonObject && newJsonObject.size() > 0) {
            JSONArray accounts = newJsonObject.getJSONArray("accounts");
            if (null != accounts && accounts.size() > 0) {
                List<Account> oldAccounts = synchronizationTaskMapperEx.selectAccount();
                List<Account> newAccounts = JSONObject.parseArray(newJsonObject.getJSONArray("accounts").toJSONString(), Account.class);
                for (Account newAccount : newAccounts) {
                    newAccount.setTenantId(tenantId);
                    for (Account oldAccount : oldAccounts) {
                        if (newAccount.getId().equals(oldAccount.getId())) {
//                            synchronizationTaskMapperEx.updateAccount(newAccount);
                            //新旧数据比对并操作后，将新数据从List中“移除”
                            newAccount = null;
                            break;
                        }
                    }
                    //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                    //没被置null说明这条新数据是新增的，需要调用接口落盘
                    if (newAccount != null) {
                        synchronizationTaskMapperEx.insertAccountSelective(newAccount);
                    }
                }
            }
        }

        //用户
        if (null != newJsonObject && newJsonObject.size() > 0) {
            JSONArray userList = newJsonObject.getJSONArray("userList");
            if (null != userList && userList.size() > 0) {
                List<User> newUser = JSONObject.parseArray(newJsonObject.getJSONArray("userList").toJSONString(), User.class);
                List<User> oldUser = synchronizationTaskMapperEx.selectUserNotTenantId();
                for (User newData : newUser) {
                    for (User oldMaterial : oldUser) {
                        if (newData.getId().equals(oldMaterial.getId())) {
                            if (!newData.getId().equals("120")) {
                                if (newData.getUpdateTime() != null) {
                                    long newTime = newData.getUpdateTime().getTime();
                                    long oldTime = 0L;
                                    if (oldMaterial.getUpdateTime() != null) {
                                        oldTime = oldMaterial.getUpdateTime().getTime();
                                    }
                                    if (newTime > oldTime) {
                                        synchronizationTaskMapperEx.updateUserTime(newData);
                                    }
                                }
//                                synchronizationTaskMapperEx.updateUserTime(newData);
                            }
                            //新旧数据比对并操作后，将新数据从List中“移除”
                            newData = null;
                            break;
                        }
                    }
                    //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                    //没被置null说明这条新数据是新增的，需要调用接口落盘
                    if (newData != null) {
                        if (!newData.getId().equals("120")) {
                            synchronizationTaskMapperEx.insertUser(newData);
                        }
                    }
                }
            }
        }
        //供应商
        if (null != newJsonObject && newJsonObject.size() > 0) {
            JSONArray suppliers = newJsonObject.getJSONArray("suppliers");
            List<Supplier> oldSuppliers = synchronizationTaskMapperEx.selectOldSupplier(tenantId, "供应商");
            if (null != suppliers && suppliers.size() > 0) {
                List<Supplier> newSuppliers = JSONObject.parseArray(newJsonObject.getJSONArray("suppliers").toJSONString(), Supplier.class);
                for (Supplier newEntity : newSuppliers) {
                    newEntity.setTenantId(tenantId);
                    for (Supplier oldEntity : oldSuppliers) {
                        if (newEntity.getId().equals(oldEntity.getId())) {
                            if (newEntity.getUpdateTime() != null) {
                                long newTime = newEntity.getUpdateTime().getTime();
                                long oldTime = 0L;
                                if (oldEntity.getUpdateTime() != null) {
                                    oldTime = oldEntity.getUpdateTime().getTime();
                                }
                                if (newTime > oldTime) {
                                    synchronizationTaskMapperEx.updateSupplierEntity(newEntity);
                                }
                            }
//                            synchronizationTaskMapperEx.updateSupplierEntity(newEntity);
                            //新旧数据比对并操作后，将新数据从List中“移除”
                            newEntity = null;
                            oldSuppliers.remove(oldEntity);
                            break;
                        }
                    }
                    //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                    //没被置null说明这条新数据是新增的，需要调用接口落盘
                    if (newEntity != null) {
                        synchronizationTaskMapperEx.insertSupplier(newEntity);
                    }
                }
            }
//            if (oldSuppliers != null && oldSuppliers.size() > 0) {
//                for (Supplier oldData : oldSuppliers) {
//                    if (oldData != null && oldData.getEnabled()) {
//                        synchronizationTaskMapperEx.updateSupplierEnabled(oldData.getId());
//                    }
//                }
//            }

        }
//        //用户类型
//        List<UserCategory> newUserCategory = JSONObject.parseArray(newJsonObject.getJSONArray("userCategoryList").toJSONString(), UserCategory.class);
//        List<UserCategory> oldUserCategory = synchronizationTaskMapperEx.selectUserCategory(tenantId);
//        for (UserCategory newData : newUserCategory) {
//            newData.setTenantId(tenantId);
//            for (UserCategory oldMaterial : oldUserCategory) {
//                if (newData.getId().equals(oldMaterial.getId())) {
//                    synchronizationTaskMapperEx.updateUserCategoryTime(newData);
//                    //新旧数据比对并操作后，将新数据从List中“移除”
//                    newData = null;
//                    break;
//                }
//            }
//            //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//            //没被置null说明这条新数据是新增的，需要调用接口落盘
//            if (newData != null) {
//                synchronizationTaskMapperEx.insertUserCategory(newData);
//            }
//        }
//        //用户/角色/模块关系表
//        List<UserBusiness> newUserBusiness = JSONObject.parseArray(newJsonObject.getJSONArray("userBusinessList").toJSONString(), UserBusiness.class);
//        List<UserBusiness> oldUserBusiness = synchronizationTaskMapperEx.selectUserBusiness(tenantId);
//        for (UserBusiness newData : newUserBusiness) {
//            newData.setTenantId(tenantId);
//            for (UserBusiness oldMaterial : oldUserBusiness) {
//                if (newData.getId().equals(oldMaterial.getId())) {
//                    synchronizationTaskMapperEx.updateUserBusinessTime(newData);
//                    //新旧数据比对并操作后，将新数据从List中“移除”
//                    newData = null;
//                    break;
//                }
//            }
//            //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//            //没被置null说明这条新数据是新增的，需要调用接口落盘
//            if (newData != null) {
//                synchronizationTaskMapperEx.insertUserBusiness(newData);
//            }
//        }
//        //角色
//        List<Role> newRole = JSONObject.parseArray(newJsonObject.getJSONArray("roleList").toJSONString(), Role.class);
//        List<Role> oldRole = synchronizationTaskMapperEx.selectRole(tenantId);
//        for (Role newData : newRole) {
//            newData.setTenantId(tenantId);
//            for (Role oldMaterial : oldRole) {
//                if (newData.getId().equals(oldMaterial.getId())) {
//                    synchronizationTaskMapperEx.updateRoleTime(newData);
//                    //新旧数据比对并操作后，将新数据从List中“移除”
//                    newData = null;
//                    break;
//                }
//            }
//            //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//            //没被置null说明这条新数据是新增的，需要调用接口落盘
//            if (newData != null) {
//                synchronizationTaskMapperEx.insertRole(newData);
//            }
//        }
        //经手人表
//        List<Person> newPerson = JSONObject.parseArray(newJsonObject.getJSONArray("personList").toJSONString(), Person.class);
//        List<Person> oldPerson = synchronizationTaskMapperEx.selectPerson(tenantId);
//        for (Person newData : newPerson) {
//            newData.setTenantId(tenantId);
//            for (Person oldMaterial : oldPerson) {
//                if (newData.getId().equals(oldMaterial.getId())) {
//                    synchronizationTaskMapperEx.updatePersonTime(newData);
//                    //新旧数据比对并操作后，将新数据从List中“移除”
//                    newData = null;
//                    break;
//                }
//            }
//            //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//            //没被置null说明这条新数据是新增的，需要调用接口落盘
//            if (newData != null) {
//                synchronizationTaskMapperEx.insertPerson(newData);
//            }
//        }
//        //机构表
//        List<Organization> newOrganization = JSONObject.parseArray(newJsonObject.getJSONArray("organizationList").toJSONString(), Organization.class);
//        List<Organization> oldOrganization = synchronizationTaskMapperEx.selectOrganization(tenantId);
//        for (Organization newData : newOrganization) {
//            newData.setTenantId(tenantId);
//            for (Organization oldMaterial : oldOrganization) {
//                if (newData.getId().equals(oldMaterial.getId())) {
//                    synchronizationTaskMapperEx.updateOrganizationTime(newData);
//                    //新旧数据比对并操作后，将新数据从List中“移除”
//                    newData = null;
//                    break;
//                }
//            }
//            //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//            //没被置null说明这条新数据是新增的，需要调用接口落盘
//            if (newData != null) {
//                synchronizationTaskMapperEx.insertOrganization(newData);
//            }
//        }
//        //机构用户关系表
//        List<OrgaUserRel> newOrgaUserRel = JSONObject.parseArray(newJsonObject.getJSONArray("orgaUserRelList").toJSONString(), OrgaUserRel.class);
//        List<OrgaUserRel> oldOrgaUserRel = synchronizationTaskMapperEx.selectOrgaUserRel(tenantId);
//        for (OrgaUserRel newData : newOrgaUserRel) {
//            newData.setTenantId(tenantId);
//            for (OrgaUserRel oldMaterial : oldOrgaUserRel) {
//                if (newData.getId().equals(oldMaterial.getId())) {
//                    synchronizationTaskMapperEx.updateOrgaUserRelTime(newData);
//                    //新旧数据比对并操作后，将新数据从List中“移除”
//                    newData = null;
//                    break;
//                }
//            }
//            //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//            //没被置null说明这条新数据是新增的，需要调用接口落盘
//            if (newData != null) {
//                synchronizationTaskMapperEx.insertOrgaUserRel(newData);
//            }
//        }
        //促销主表
        if (null != newJsonObject && newJsonObject.size() > 0) {
            JSONArray promotionHeadList = newJsonObject.getJSONArray("promotionHeadList");
            List<PromotionHead> oldPromotionHead = synchronizationTaskMapperEx.selectPromotionHead(tenantId);
            if (null != promotionHeadList && promotionHeadList.size() > 0) {
                List<PromotionHead> newPromotionHead = JSONObject.parseArray(newJsonObject.getJSONArray("promotionHeadList").toJSONString(), PromotionHead.class);
                Map<String, List<PromotionItem>> promotionItemMap = JSONObject.parseObject(newJsonObject.getJSONObject("promotionItemMap").toJSONString())
                        .entrySet().stream()
                        .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), PromotionItem.class)));

                Map<String, List<PromotionGift>> promotionGiftMap = JSONObject.parseObject(newJsonObject.getJSONObject("promotionGiftMap").toJSONString())
                        .entrySet().stream()
                        .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), PromotionGift.class)));
                Map<String, List<PromotionSupplier>> promotionSupplierMap = JSONObject.parseObject(newJsonObject.getJSONObject("promotionSupplierMap").toJSONString())
                        .entrySet().stream()
                        .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), PromotionSupplier.class)));
                for (PromotionHead newData : newPromotionHead) {
                    newData.setTenantId(tenantId);
                    for (PromotionHead oldData : oldPromotionHead) {
                        if (newData.getId().equals(oldData.getId())) {
                            synchronizationTaskMapperEx.updatePromotionHeadTime(newData);
                            List<PromotionItem> promotionItems = promotionItemMap.get(newData.getId());
                            if (null != promotionItems && promotionItems.size() > 0) {
                                Set<String> itemSets = Sets.newHashSet();
                                List<PromotionItem> existsVOS =  synchronizationTaskMapperEx.selectPromotionItemTime(newData.getId());
                                existsVOS.forEach(existsVO -> {
                                    itemSets.add(existsVO.getId());
                                });
                                for (PromotionItem item : promotionItems) {
                                    if (itemSets.contains(item.getId())) {
                                        itemSets.remove(item.getId());
                                        synchronizationTaskMapperEx.updatePromotionItemByPrimaryKeySelective(item);
                                    } else {
                                        synchronizationTaskMapperEx.insertPromotionItemSelective(item);
                                    }
                                }
                                if (newData.getPromotionType() == 3) {
                                    for (PromotionItem promotionItem : promotionItems) {
                                        List<PromotionGift> newPromotionGifts = promotionGiftMap.get(promotionItem.getId());
                                        if (null != newPromotionGifts){
                                            List<PromotionGift> oldPromotionGifts = synchronizationTaskMapperEx.selectPromotionGiftTime(promotionItem.getId());
                                            Set<String> giftsSets = Sets.newHashSet();
                                            oldPromotionGifts.forEach(existsVO -> {
                                                giftsSets.add(existsVO.getId());
                                            });
                                            if (newPromotionGifts.size() > 0) {
                                                for (PromotionGift item : newPromotionGifts) {
                                                    if (giftsSets.contains(item.getId())) {
                                                        giftsSets.remove(item.getId());
                                                        synchronizationTaskMapperEx.updatePromotionGiftByPrimaryKeySelective(item);
                                                    }else {
                                                        synchronizationTaskMapperEx.insertPromotionGiftSelective(item);
                                                    }
                                                }
                                            }
                                            for (String itemId : giftsSets) {
                                                synchronizationTaskMapperEx.batchDeletePromotionGiftByItemId(itemId);
                                            }
                                        }
                                    }
                                }
                                for (String itemId : itemSets) {
                                    synchronizationTaskMapperEx.batchDeletePromotionItemById(itemId);
                                }
                            }
                            List<PromotionSupplier> newPromotionSuppliers = promotionSupplierMap.get(newData.getId());
                            if (null != newPromotionSuppliers){
                                List<PromotionSupplier> oldPromotionSupplierList = synchronizationTaskMapperEx.selectPromotionSupplierTime(newData.getId());
                                Set<String> supplierSets = Sets.newHashSet();
                                oldPromotionSupplierList.forEach(existsVO -> {
                                    supplierSets.add(existsVO.getId());
                                });
                                if (newPromotionSuppliers.size() > 0) {
                                    for (PromotionSupplier supplier : newPromotionSuppliers) {
                                        if (supplierSets.contains(supplier.getId())) {
                                            supplierSets.remove(supplier.getId());
                                            synchronizationTaskMapperEx.updatePromotionSupplierByPrimaryKeySelective(supplier);
                                        }else {
                                            synchronizationTaskMapperEx.insertPromotionSupplierSelective(supplier);
                                        }
                                    }
                                }
                                for (String itemId : supplierSets) {
                                    synchronizationTaskMapperEx.batchDeletePromotionSupplierById(itemId);
                                }
                            }
                            //新旧数据比对并操作后，将新数据从List中“移除”
                            newData = null;
                            oldPromotionHead.remove(oldData);
                            break;
                        }
                    }
                    //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                    //没被置null说明这条新数据是新增的，需要调用接口落盘
                    if (newData != null) {
                        synchronizationTaskMapperEx.insertPromotionHead(newData);
                        List<PromotionItem> promotionItems = promotionItemMap.get(newData.getId());
                        if (null != promotionItems && promotionItems.size() > 0) {
                            synchronizationTaskMapperEx.insertPromotionItem(promotionItems, tenantId);
                            if (newData.getPromotionType() == 3) {
                                for (PromotionItem promotionItem : promotionItems) {
                                    List<PromotionGift> promotionGifts = promotionGiftMap.get(promotionItem.getId());
                                    synchronizationTaskMapperEx.insertPromotionGift(promotionGifts, tenantId);
                                }
                            }
                            List<PromotionSupplier> promotionSuppliers = promotionSupplierMap.get(newData.getId());
                            if (null != promotionSuppliers && promotionSuppliers.size() > 0) {
                                synchronizationTaskMapperEx.insertPromotionSupplierTime(promotionSuppliers, tenantId);
                            }
                        }
                    }
                }
            }
            if (oldPromotionHead != null && oldPromotionHead.size() > 0) {
                for (PromotionHead oldData : oldPromotionHead) {
                    if (oldData != null && "0".equals(oldData.getDeleteFlag())) {
                        synchronizationTaskMapperEx.deletePromotionHead(oldData.getId());
                    }
                }
            }

        }
        //返利
        if (null != newJsonObject && newJsonObject.size() > 0) {
            JSONArray rebates = newJsonObject.getJSONArray("rebates");
            List<Rebate> oldRebates = synchronizationTaskMapperEx.selectRebate(tenantId);
            if (null != rebates && rebates.size() > 0) {
                List<Rebate> newRebates = JSONObject.parseArray(newJsonObject.getJSONArray("rebates").toJSONString(), Rebate.class);
                Map<String, List<RebateItem>> rebateItemMap = JSONObject.parseObject(newJsonObject.getJSONObject("rebateItemMap").toJSONString())
                        .entrySet().stream()
                        .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), RebateItem.class)));

                for (Rebate newData : newRebates) {
                    newData.setTenantId(tenantId);
                    for (Rebate oldData : oldRebates) {
                        if (newData.getId().equals(oldData.getId())) {
                            synchronizationTaskMapperEx.updateRebateByPrimaryKeySelective(newData);
                            List<RebateItem> rebateItems = rebateItemMap.get(newData.getId());
                            if (null != rebateItems && rebateItems.size() > 0) {
                                synchronizationTaskMapperEx.updateRebateItemTime(rebateItems, tenantId);
                            }
                            //新旧数据比对并操作后，将新数据从List中“移除”
                            newData = null;
                            oldRebates.remove(oldData);
                            break;
                        }
                    }
                    //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                    //没被置null说明这条新数据是新增的，需要调用接口落盘
                    if (newData != null) {
                        synchronizationTaskMapperEx.insertRebateSelective(newData);
                        List<RebateItem> rebateItems = rebateItemMap.get(newData.getId());
                        if (null != rebateItems && rebateItems.size() > 0) {
                            synchronizationTaskMapperEx.insertRebateItemTime(rebateItems, tenantId);
                        }
                    }
                }
            }
            if (oldRebates != null && oldRebates.size() > 0) {
                for (Rebate oldData : oldRebates) {
                    if (oldData != null && "0".equals(oldData.getDeleteFlag())) {
                        synchronizationTaskMapperEx.deleteRebate(oldData.getId());
                    }
                }
            }

        }

//        //单位
//        if (null != newJsonObject && newJsonObject.size() > 0) {
//            JSONArray unitMap = newJsonObject.getJSONArray("unitMap");
//            if (null != unitMap && unitMap.size() > 0) {
//                List<Unit> oldUnit = synchronizationTaskMapperEx.selectUnitByTime();
//                List<Unit> newUnit = JSONObject.parseArray(newJsonObject.getJSONArray("unitMap").toJSONString(), Unit.class);
//                for (Unit newEntity : newUnit) {
//                    newEntity.setTenantId(tenantId);
//                    for (Unit oldEntity : oldUnit) {
//                        if (newEntity.getId().equals(oldEntity.getId())) {
//                            synchronizationTaskMapperEx.updateUnitTime(newEntity);
//                            //新旧数据比对并操作后，将新数据从List中“移除”
//                            newEntity = null;
//                            break;
//                        }
//                    }
//                    //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
//                    //没被置null说明这条新数据是新增的，需要调用接口落盘
//                    if (newEntity != null) {
//                        synchronizationTaskMapperEx.insertUnit(newEntity);
//                    }
//                }
//            }
//        }

        //商品
        if (null != newJsonObject && newJsonObject.size() > 0 && flag) {
            JSONArray materials = newJsonObject.getJSONArray("materials");
            List<Material> oldMaterials = synchronizationTaskMapperEx.selectMaterial(tenantId);
            if (null != materials && materials.size() > 0) {
                List<Material> newMaterials = JSONObject.parseArray(newJsonObject.getJSONArray("materials").toJSONString(), Material.class);

                Map<String, Unit> unitMap = JSONObject.parseObject(newJsonObject.getJSONObject("unitMap").toJSONString(), new TypeReference<Map<String, Unit>>() {
                });

                Map<String, List<Attachment>> attachmentMap = JSONObject.parseObject(newJsonObject.getJSONObject("attachmentMap").toJSONString())
                        .entrySet().stream()
                        .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), Attachment.class)));

                Map<String, List<MaterialExtend>> materialExtendMap = JSONObject.parseObject(newJsonObject.getJSONObject("materialExtendMap").toJSONString())
                        .entrySet().stream()
                        .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), MaterialExtend.class)));
                for (Material newEntity : newMaterials) {
                    newEntity.setTenantId(tenantId);
                    for (Material oldEntity : oldMaterials) {
                        if (newEntity.getId().equals(oldEntity.getId())) {
                            if (newEntity.getUpdateTime() != null) {
                                long newTime = newEntity.getUpdateTime().getTime();
                                long oldTime =0L;
                                if (oldEntity.getUpdateTime()!=null){
                                    oldTime = oldEntity.getUpdateTime().getTime();
                                }
                                if (newTime > oldTime) {
                                    synchronizationTaskMapperEx.updateMaterialByPrimaryKeySelective(newEntity);
                                    List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                                    if (null != attachments && attachments.size() > 0) {
                                        synchronizationTaskMapperEx.updateAttachmentList(attachments, tenantId);
                                    }
                                    List<MaterialExtend> materialExtends = materialExtendMap.get(newEntity.getId());
                                    if (null != materialExtends && materialExtends.size() > 0) {
                                        synchronizationTaskMapperEx.updateMaterialExtendList(materialExtends, tenantId);
                                    }
                                    Unit unit = unitMap.get(newEntity.getId());
                                    unit.setTenantId(tenantId);
                                    List<Unit> units = synchronizationTaskMapperEx.selectUnitById(unit.getId());
                                    if (units != null && units.size() > 0) {
                                        synchronizationTaskMapperEx.updateUnitTime(unit);
                                    } else {
                                        synchronizationTaskMapperEx.insertUnit(unit);
                                    }
                                }
                            }
//                            synchronizationTaskMapperEx.updateMaterialByPrimaryKeySelective(newEntity);
//                            List<Attachment> attachments = attachmentMap.get(newEntity.getId());
//                            if (null != attachments && attachments.size() > 0) {
//                                synchronizationTaskMapperEx.updateAttachmentList(attachments, tenantId);
//                            }
//                            List<MaterialExtend> materialExtends = materialExtendMap.get(newEntity.getId());
//                            if (null != materialExtends && materialExtends.size() > 0) {
//                                synchronizationTaskMapperEx.updateMaterialExtendList(materialExtends, tenantId);
//                            }
//                            Unit unit = unitMap.get(newEntity.getId());
//                            unit.setTenantId(tenantId);
//                            List<Unit> units = synchronizationTaskMapperEx.selectUnitById(unit.getId());
//                            if (units != null && units.size() > 0) {
//                                synchronizationTaskMapperEx.updateUnitTime(unit);
//                            } else {
//                                synchronizationTaskMapperEx.insertUnit(unit);
//                            }

                            //新旧数据比对并操作后，将这个数据从List中“移除”
                            newEntity = null;
                            oldMaterials.remove(oldEntity);
                            break;
                        }
                    }
                    //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                    //没被置null说明这条新数据是新增的，需要调用接口落盘
                    if (newEntity != null) {
                        synchronizationTaskMapperEx.insertMaterialSelective(newEntity);
                        List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                        if (null != attachments && attachments.size() > 0) {
                            synchronizationTaskMapperEx.insertAttachmentList(attachments, tenantId);
                        }
                        List<MaterialExtend> materialExtends = materialExtendMap.get(newEntity.getId());
                        if (null != materialExtends && materialExtends.size() > 0) {
                            synchronizationTaskMapperEx.insertMaterialExtendList(materialExtends, tenantId);
                        }
                        Unit unit = unitMap.get(newEntity.getId());
                        unit.setTenantId(tenantId);
                        List<Unit> units = synchronizationTaskMapperEx.selectUnitById(unit.getId());
                        if (units != null && units.size() > 0) {
                            synchronizationTaskMapperEx.updateUnitTime(unit);
                        } else {
                            synchronizationTaskMapperEx.insertUnit(unit);
                        }
                    }
                }
            }
//            if (oldMaterials != null && oldMaterials.size() > 0) {
//                List<String> idList = oldMaterials.stream().map(Material::getId).collect(Collectors.toList());
//                synchronizationTaskMapperEx.updateMaterialEnabled(idList);
//            }

        }


        if (null != newJsonObject && newJsonObject.size() > 0) {
            JSONArray materialCategories = newJsonObject.getJSONArray("materialCategories");
            if (null != materialCategories && materialCategories.size() > 0) {
                //商品类型
                List<MaterialCategory> oldMaterialCategories = synchronizationTaskMapperEx.selectMaterialCategory(tenantId);
                List<MaterialCategory> newMaterialCategories = JSONObject.parseArray(newJsonObject.getJSONArray("materialCategories").toJSONString(), MaterialCategory.class);
                for (MaterialCategory newEntity : newMaterialCategories) {
                    newEntity.setTenantId(tenantId);
                    for (MaterialCategory oldEntity : oldMaterialCategories) {
                        if (newEntity.getId().equals(oldEntity.getId())) {
                            if (newEntity.getUpdateTime() != null) {
                                long newTime = newEntity.getUpdateTime().getTime();
                                long oldTime = 0L;
                                if (oldEntity.getUpdateTime() != null) {
                                    oldTime = oldEntity.getUpdateTime().getTime();
                                }
                                if (newTime > oldTime) {
                                    synchronizationTaskMapperEx.updateMaterialCategoryTime(newEntity);
                                }
                            }
//                            synchronizationTaskMapperEx.updateMaterialCategoryTime(newEntity);
                            //新旧数据比对并操作后，将新数据从List中“移除”
                            newEntity = null;
                            break;
                        }
                    }
                    //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                    //没被置null说明这条新数据是新增的，需要调用接口落盘
                    if (newEntity != null) {
                        synchronizationTaskMapperEx.insertMaterialCategory(newEntity);
                    }
                }
            }
        }

        //仓库
        if (null != newJsonObject && newJsonObject.size() > 0) {
            JSONArray depotList = newJsonObject.getJSONArray("depotList");
            if (null != depotList && depotList.size() > 0) {
                List<Depot> newDepot = JSONObject.parseArray(depotList.toJSONString(), Depot.class);
                List<Depot> oldDepot = synchronizationTaskMapperEx.selectDepotTime();
                for (Depot newData : newDepot) {
                    for (Depot oldMaterial : oldDepot) {
                        if (newData.getId().equals(oldMaterial.getId())) {
                            if (!newData.getName().equals(oldMaterial.getName())) {
                                synchronizationTaskMapperEx.updateDepotTime(newData);
                            }
                            //新旧数据比对并操作后，将新数据从List中“移除”
                            newData = null;
                            break;
                        }
                    }
                    //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                    //没被置null说明这条新数据是新增的，需要调用接口落盘
                    if (newData != null) {
                        synchronizationTaskMapperEx.insertDepot(newData);
                    }
                }
            }
            if (null != newJsonObject && newJsonObject.size() > 0) {
                JSONArray userCategories = newJsonObject.getJSONArray("userCategories");
                if (null != userCategories && userCategories.size() > 0) {
                    //用户类型
                    List<UserCategory> oldUserCategories = synchronizationTaskMapperEx.selectUserCategoryTime();
                    List<UserCategory> newUserCategories = JSONObject.parseArray(newJsonObject.getJSONArray("userCategories").toJSONString(), UserCategory.class);
                    for (UserCategory newEntity : newUserCategories) {
                        for (UserCategory oldEntity : oldUserCategories) {
                            if (newEntity.getId().equals(oldEntity.getId())) {
                                synchronizationTaskMapperEx.updateUserCategoryTime(newEntity);
                                //新旧数据比对并操作后，将新数据从List中“移除”
                                newEntity = null;
                                break;
                            }
                        }
                        //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                        //没被置null说明这条新数据是新增的，需要调用接口落盘
                        if (newEntity != null) {
                            synchronizationTaskMapperEx.insertUserCategory(newEntity);
                        }
                    }
                }
            }

            if (flag) {
                JSONArray auditSynchronizationList = newJsonObject.getJSONArray("auditSynchronizationList");
                if (null != auditSynchronizationList && auditSynchronizationList.size() > 0) {
                    List<AuditSynchronization> newAuditSynchronization = JSONObject.parseArray(auditSynchronizationList.toJSONString(), AuditSynchronization.class);
                    if (null != newAuditSynchronization) {
                        for (AuditSynchronization auditSynchronization : newAuditSynchronization) {
                            workflowConfigProcessService.ApproveType(auditSynchronization.getApproveType()
                                    , auditSynchronization.getProcessId(), auditSynchronization.getApproveMsg(), auditSynchronization.getCreateBy());
                        }
                    }
                    List<String> auditIdList = JSONObject.parseArray(newJsonObject.getJSONArray("auditSynchronizationList").toJSONString(), AuditSynchronization.class)
                            .stream()
                            .map(AuditSynchronization::getId)
                            .collect(Collectors.toList());
                    User user = userService.getManager();
                    if (user != null) {
                        String remark = user.getRemark();
                        String upUrl = remark + auditUrl;
                        JSONObject object = new JSONObject();
                        String ids = StringUtil.listToString(auditIdList);
                        object.put("ids", ids);
                        NoticeUtil.sendPost(upUrl, object);
                    }
                }
            }
        }

    }

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    public void synchronizationAllocation(JSONObject newJsonObject, HttpServletRequest request) {
        try {
            if (null != newJsonObject && newJsonObject.size() > 0) {
                JSONObject attachmentMap1 = newJsonObject.getJSONObject("attachmentMap");
                Map<String, List<Attachment>> attachmentMap = new HashMap<>();
                if (null != attachmentMap1 && attachmentMap1.size() > 0) {
                    attachmentMap = JSONObject.parseObject(newJsonObject.getJSONObject("attachmentMap").toJSONString())
                            .entrySet().stream()
                            .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), Attachment.class)));
                }
                //要货申请
                JSONArray applyDepotHead = newJsonObject.getJSONArray("applyDepotHead");
                if (null != applyDepotHead && applyDepotHead.size() > 0) {
                    List<DepotHead> oldApplyDepotHead = synchronizationTaskMapperEx.selectOldDepotHeadByType(tenantId, "要货申请");
                    List<DepotHead> newApplyDepotHead = JSONObject.parseArray(newJsonObject.getJSONArray("applyDepotHead").toJSONString(), DepotHead.class);
                    Map<String, List<DepotItem>> applyDepotMap = JSONObject.parseObject(newJsonObject.getJSONObject("applyDepotMap").toJSONString())
                            .entrySet().stream()
                            .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), DepotItem.class)));

                    for (DepotHead newEntity : newApplyDepotHead) {
                        if (!tenantId.equals(newEntity.getTenantId())) {
                            newEntity.setUploadFlag("1");
                            //                newEntity.setTenantId(tenantId);
                            newEntity.setTenantId(tenantId);
                            for (DepotHead oldEntity : oldApplyDepotHead) {
                                if (newEntity.getId().equals(oldEntity.getId())) {
                                    synchronizationTaskMapperEx.updateDepotHeadByPrimaryKeySelective(newEntity);
                                    List<DepotItem> newDepotItems = applyDepotMap.get(newEntity.getId());
                                    for (DepotItem depotItem : newDepotItems) {
                                        MaterialVo4Unit materialByColor = synchronizationTaskMapperEx.getMaterialByColor(depotItem.getCustom2(), 1, tenantId);
                                        if (materialByColor != null) {
                                            depotItem.setMaterialId(materialByColor.getId());
                                            depotItem.setMaterialExtendId(materialByColor.getMeId());
                                            depotItem.setMaterialUnit(materialByColor.getUnitName());
                                            double newRatio = materialByColor.getRatio().doubleValue() / depotItem.getCustom13().doubleValue();
                                            BigDecimal divide = depotItem.getOperNumber().divide(new BigDecimal(newRatio), BigDecimal.ROUND_UP, 2);
                                            divide=divide.setScale( 0, BigDecimal.ROUND_HALF_UP );
                                            depotItem.setOperNumber(divide);
                                            depotItem.setBasicNumber(divide);
                                            depotItem.setUploadFlag("1");
                                            depotItem.setTenantId(tenantId);
                                        }
                                    }
                                    List<DepotItem> oldDepotItems = synchronizationTaskMapperEx.getItemListByHeaderId(newEntity.getId());
                                    Set<String> applySets = Sets.newHashSet();
                                    oldDepotItems.forEach(existsVO -> {
                                        applySets.add(existsVO.getId());
                                    });
                                    if (newDepotItems.size() > 0) {
                                        for (DepotItem depotItem : newDepotItems) {
                                            if (applySets.contains(depotItem.getId())) {
                                                applySets.remove(depotItem.getId());
                                                synchronizationTaskMapperEx.updateDepotItemByPrimaryKeySelective(depotItem);
                                            }else {
                                                synchronizationTaskMapperEx.insertDepotItemSelective(depotItem);
                                            }
                                        }
                                    }
//                                    synchronizationTaskMapperEx.updateDepotItemList(newDepotItems, tenantId);
                                    //新旧数据比对并操作后，将新数据从List中“移除”
                                    List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                                    if (attachments.size() > 0) {
                                        synchronizationTaskMapperEx.updateAttachmentList(attachments, tenantId);
                                    }
                                    newEntity = null;
                                    break;
                                }
                            }
                            //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                            //没被置null说明这条新数据是新增的，需要调用接口落盘
                            if (newEntity != null) {
                                synchronizationTaskMapperEx.insertDepotHeadSelective(newEntity);
                                List<DepotItem> depotItems = applyDepotMap.get(newEntity.getId());
                                for (DepotItem depotItem : depotItems) {
                                    MaterialVo4Unit materialByColor = synchronizationTaskMapperEx.getMaterialByColor(depotItem.getCustom2(), 1, tenantId);
                                    if (materialByColor != null) {
                                        depotItem.setMaterialId(materialByColor.getId());
                                        depotItem.setMaterialExtendId(materialByColor.getMeId());
                                        depotItem.setMaterialUnit(materialByColor.getUnitName());
                                        double newRatio = materialByColor.getRatio().doubleValue() / depotItem.getCustom13().doubleValue();
                                        BigDecimal divide = depotItem.getOperNumber().divide(new BigDecimal(newRatio), BigDecimal.ROUND_UP, 2);
                                        divide=divide.setScale( 0, BigDecimal.ROUND_HALF_UP );
                                        depotItem.setOperNumber(divide);
                                        depotItem.setBasicNumber(divide);
                                        if (materialByColor.getPurchaseDecimal()!=null &&
                                            materialByColor.getPurchaseDecimal().compareTo(BigDecimal.ZERO)>0){
                                            BigDecimal purchaseDecimal = materialByColor.getPurchaseDecimal();
                                            depotItem.setUnitPrice(purchaseDecimal);
                                            BigDecimal allPrice = purchaseDecimal.multiply(divide);
                                            depotItem.setAllPrice(allPrice);
                                            depotItem.setTaxLastMoney(allPrice);
                                        }
                                        depotItem.setCustom13(materialByColor.getRatio());
                                        depotItem.setUploadFlag("1");
                                    }
                                }
                                synchronizationTaskMapperEx.insertDepotItemList(depotItems, tenantId);
                                List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                                if (attachments.size() > 0) {
                                    synchronizationTaskMapperEx.insertAttachmentList(attachments, tenantId);
                                }
                            }
                        }

                    }
                }
                JSONArray deliveryDepotHead = newJsonObject.getJSONArray("deliveryDepotHead");
                if (null != deliveryDepotHead && deliveryDepotHead.size() > 0) {
                    List<DepotHead> oldDeliveryDepotHead = synchronizationTaskMapperEx.selectOldDepotHeadByType(tenantId, "配送");
                    List<DepotHead> newDeliveryDepotHead = JSONObject.parseArray(newJsonObject.getJSONArray("deliveryDepotHead").toJSONString(), DepotHead.class);
                    Map<String, List<DepotItem>> deliveryDepotMap = JSONObject.parseObject(newJsonObject.getJSONObject("deliveryDepotMap").toJSONString())
                            .entrySet().stream()
                            .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), DepotItem.class)));

                    for (DepotHead newEntity : newDeliveryDepotHead) {
                        if (!tenantId.equals(newEntity.getTenantId())) {
                            newEntity.setUploadFlag("1");
                            //                newEntity.setTenantId(tenantId);
                            newEntity.setTenantId(tenantId);
                            for (DepotHead oldEntity : oldDeliveryDepotHead) {
                                if (newEntity.getId().equals(oldEntity.getId())) {
                                    synchronizationTaskMapperEx.updateDepotHeadByPrimaryKeySelective(newEntity);
                                    List<DepotItem> newDepotItems = deliveryDepotMap.get(newEntity.getId());
                                    for (DepotItem depotItem : newDepotItems) {
                                        MaterialVo4Unit materialByColor = synchronizationTaskMapperEx.getMaterialByColor(depotItem.getCustom2(), 2, tenantId);
                                        if (materialByColor != null) {
                                            depotItem.setMaterialId(materialByColor.getId());
                                            depotItem.setMaterialExtendId(materialByColor.getMeId());
                                            depotItem.setMaterialUnit(materialByColor.getUnitName());
                                            double newRatio = depotItem.getCustom13().doubleValue() / materialByColor.getRatio().doubleValue();
                                            BigDecimal divide = depotItem.getOperNumber().multiply(new BigDecimal(newRatio));
                                            divide=divide.setScale( 0, BigDecimal.ROUND_HALF_UP );
                                            depotItem.setOperNumber(divide);
                                            depotItem.setBasicNumber(divide);
                                            depotItem.setUploadFlag("1");
                                            depotItem.setTenantId(tenantId);
                                        }
                                    }
                                    List<DepotItem> oldDepotItems = synchronizationTaskMapperEx.getItemListByHeaderId(newEntity.getId());
                                    Set<String> applySets = Sets.newHashSet();
                                    oldDepotItems.forEach(existsVO -> {
                                        applySets.add(existsVO.getId());
                                    });
                                    if (newDepotItems.size() > 0) {
                                        for (DepotItem depotItem : newDepotItems) {
                                            if (applySets.contains(depotItem.getId())) {
                                                applySets.remove(depotItem.getId());
                                                synchronizationTaskMapperEx.updateDepotItemByPrimaryKeySelective(depotItem);
                                            }else {
                                                synchronizationTaskMapperEx.insertDepotItemSelective(depotItem);
                                            }
                                        }
                                    }
//                                    synchronizationTaskMapperEx.updateDepotItemList(depotItems, tenantId);
                                    //新旧数据比对并操作后，将新数据从List中“移除”
                                    List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                                    if (attachments.size() > 0) {
                                        synchronizationTaskMapperEx.updateAttachmentList(attachments, tenantId);
                                    }
                                    //新旧数据比对并操作后，将新数据从List中“移除”
                                    newEntity = null;
                                    break;
                                }
                            }
                            //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                            //没被置null说明这条新数据是新增的，需要调用接口落盘
                            if (newEntity != null) {
                                synchronizationTaskMapperEx.insertDepotHeadSelective(newEntity);
                                List<DepotItem> depotItems = deliveryDepotMap.get(newEntity.getId());
                                for (DepotItem depotItem : depotItems) {
                                    MaterialVo4Unit materialByColor = synchronizationTaskMapperEx.getMaterialByColor(depotItem.getCustom2(), 2, tenantId);
                                    if (materialByColor != null) {
                                        depotItem.setMaterialId(materialByColor.getId());
                                        depotItem.setMaterialExtendId(materialByColor.getMeId());
                                        depotItem.setMaterialUnit(materialByColor.getUnitName());
                                        double newRatio = depotItem.getCustom13().doubleValue() / materialByColor.getRatio().doubleValue();
                                        BigDecimal divide = depotItem.getOperNumber().multiply(new BigDecimal(newRatio));
                                        divide=divide.setScale( 0, BigDecimal.ROUND_HALF_UP );
                                        depotItem.setOperNumber(divide);
                                        depotItem.setBasicNumber(divide);
                                        if (materialByColor.getPurchaseDecimal()!=null &&
                                                materialByColor.getPurchaseDecimal().compareTo(BigDecimal.ZERO)>0){
                                            BigDecimal purchaseDecimal = materialByColor.getPurchaseDecimal();
                                            depotItem.setUnitPrice(purchaseDecimal);
                                            BigDecimal allPrice = purchaseDecimal.multiply(divide);
                                            depotItem.setAllPrice(allPrice);
                                            depotItem.setTaxLastMoney(allPrice);
                                        }
                                        depotItem.setCustom13(materialByColor.getRatio());
                                        depotItem.setUploadFlag("1");
                                    }
                                }
                                synchronizationTaskMapperEx.insertDepotItemList(depotItems, tenantId);
                                List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                                if (attachments.size() > 0) {
                                    synchronizationTaskMapperEx.insertAttachmentList(attachments, tenantId);
                                }
                                if (StringUtil.isNotEmpty(newEntity.getLinkNumber())) {
                                    String billStatus = depotItemService.getBillStatusByParam(newEntity);
                                    depotItemService.changeBillStatus(newEntity, billStatus);
                                }
                            }

                        }
                    }
                }
                JSONArray acceptanceDepotHead = newJsonObject.getJSONArray("acceptanceDepotHead");
                if (null != acceptanceDepotHead && acceptanceDepotHead.size() > 0) {
                    List<DepotHead> oldAcceptanceDepotHead = synchronizationTaskMapperEx.selectOldDepotHeadByType(tenantId, "验收");
                    List<DepotHead> newAcceptanceDepotHead = JSONObject.parseArray(newJsonObject.getJSONArray("acceptanceDepotHead").toJSONString(), DepotHead.class);
                    Map<String, List<DepotItem>> acceptanceDepotMap = JSONObject.parseObject(newJsonObject.getJSONObject("acceptanceDepotMap").toJSONString())
                            .entrySet().stream()
                            .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), DepotItem.class)));

                    for (DepotHead newEntity : newAcceptanceDepotHead) {
                        if (!tenantId.equals(newEntity.getTenantId())) {
                            newEntity.setUploadFlag("1");
                            //                newEntity.setTenantId(tenantId);
                            newEntity.setTenantId(tenantId);
                            for (DepotHead oldEntity : oldAcceptanceDepotHead) {
                                if (newEntity.getId().equals(oldEntity.getId())) {
                                    synchronizationTaskMapperEx.updateDepotHeadByPrimaryKeySelective(newEntity);
                                    List<DepotItem> newDepotItems = acceptanceDepotMap.get(newEntity.getId());
                                    for (DepotItem depotItem : newDepotItems) {
                                        MaterialVo4Unit materialByColor = synchronizationTaskMapperEx.getMaterialByColor(depotItem.getCustom2(), 1, tenantId);
                                        if (materialByColor != null) {
                                            depotItem.setMaterialId(materialByColor.getId());
                                            depotItem.setMaterialExtendId(materialByColor.getMeId());
                                            depotItem.setMaterialUnit(materialByColor.getUnitName());
                                            double newRatio = materialByColor.getRatio().doubleValue() / depotItem.getCustom13().doubleValue();
                                            BigDecimal divide = depotItem.getOperNumber().divide(new BigDecimal(newRatio), BigDecimal.ROUND_UP, 2);
                                            divide=divide.setScale( 0, BigDecimal.ROUND_HALF_UP );
                                            depotItem.setOperNumber(divide);
                                            depotItem.setBasicNumber(divide);
                                            depotItem.setUploadFlag("1");
                                            depotItem.setTenantId(tenantId);
                                        }

                                    }
                                    List<DepotItem> oldDepotItems = synchronizationTaskMapperEx.getItemListByHeaderId(newEntity.getId());
                                    Set<String> applySets = Sets.newHashSet();
                                    oldDepotItems.forEach(existsVO -> {
                                        applySets.add(existsVO.getId());
                                    });
                                    if (newDepotItems.size() > 0) {
                                        for (DepotItem depotItem : newDepotItems) {
                                            if (applySets.contains(depotItem.getId())) {
                                                applySets.remove(depotItem.getId());
                                                synchronizationTaskMapperEx.updateDepotItemByPrimaryKeySelective(depotItem);
                                            }else {
                                                synchronizationTaskMapperEx.insertDepotItemSelective(depotItem);
                                            }
                                        }
                                    }
//                                    synchronizationTaskMapperEx.updateDepotItemList(depotItems, tenantId);

                                    List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                                    if (attachments.size() > 0) {
                                        synchronizationTaskMapperEx.updateAttachmentList(attachments, tenantId);
                                    }
                                    //新旧数据比对并操作后，将新数据从List中“移除”
                                    newEntity = null;
                                    break;
                                }
                            }
                            //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                            //没被置null说明这条新数据是新增的，需要调用接口落盘
                            if (newEntity != null) {
                                synchronizationTaskMapperEx.insertDepotHeadSelective(newEntity);
                                List<DepotItem> depotItems = acceptanceDepotMap.get(newEntity.getId());
                                for (DepotItem depotItem : depotItems) {
                                    MaterialVo4Unit materialByColor = synchronizationTaskMapperEx.getMaterialByColor(depotItem.getCustom2(), 1, tenantId);
                                    if (materialByColor != null) {
                                        depotItem.setMaterialId(materialByColor.getId());
                                        depotItem.setMaterialExtendId(materialByColor.getMeId());
                                        depotItem.setMaterialUnit(materialByColor.getUnitName());
                                        double newRatio = materialByColor.getRatio().doubleValue() / depotItem.getCustom13().doubleValue();
                                        BigDecimal divide = depotItem.getOperNumber().divide(new BigDecimal(newRatio), BigDecimal.ROUND_UP, 2);
                                        divide=divide.setScale( 0, BigDecimal.ROUND_HALF_UP );
                                        depotItem.setOperNumber(divide);
                                        depotItem.setBasicNumber(divide);
                                        if (materialByColor.getPurchaseDecimal()!=null &&
                                                materialByColor.getPurchaseDecimal().compareTo(BigDecimal.ZERO)>0){
                                            BigDecimal purchaseDecimal = materialByColor.getPurchaseDecimal();
                                            depotItem.setUnitPrice(purchaseDecimal);
                                            BigDecimal allPrice = purchaseDecimal.multiply(divide);
                                            depotItem.setAllPrice(allPrice);
                                            depotItem.setTaxLastMoney(allPrice);
                                        }
                                        depotItem.setCustom13(materialByColor.getRatio());
                                        depotItem.setUploadFlag("1");
                                    }
                                }
                                synchronizationTaskMapperEx.insertDepotItemList(depotItems, tenantId);
                                List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                                if (attachments.size() > 0) {
                                    synchronizationTaskMapperEx.insertAttachmentList(attachments, tenantId);
                                }
                                String billStatus = depotItemService.getBillStatusByParam(newEntity);
                                depotItemService.changeBillStatus(newEntity, billStatus);
                            }
                        }
                    }
                }
                //采购订单
                JSONArray purchaseDepotHead = newJsonObject.getJSONArray("purchaseDepotHead");
                if (null != purchaseDepotHead && purchaseDepotHead.size() > 0) {
                    List<DepotHead> oldPurchaseDepotHead = synchronizationTaskMapperEx.selectOldDepotHeadByType(tenantId, "采购订单");
                    List<DepotHead> newPurchaseDepotHead = JSONObject.parseArray(newJsonObject.getJSONArray("purchaseDepotHead").toJSONString(), DepotHead.class);
                    Map<String, List<DepotItem>> purchaseDepotMap = JSONObject.parseObject(newJsonObject.getJSONObject("purchaseDepotMap").toJSONString())
                            .entrySet().stream()
                            .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), DepotItem.class)));

                    for (DepotHead newEntity : newPurchaseDepotHead) {
                        newEntity.setUploadFlag("1");
                        newEntity.setTenantId(tenantId);
                        for (DepotHead oldEntity : oldPurchaseDepotHead) {
                            if (newEntity.getId().equals(oldEntity.getId())) {
                                //新旧数据比对并操作后，将新数据从List中“移除”
                                synchronizationTaskMapperEx.updateDepotHeadByPrimaryKeySelective(newEntity);
                                List<DepotItem> depotItems = purchaseDepotMap.get(newEntity.getId());
                                if (depotItems != null && depotItems.size() > 0) {
                                    synchronizationTaskMapperEx.updateDepotItemList(depotItems, newEntity.getCustom5());
                                }
                                List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                                if (attachments.size() > 0) {
                                    synchronizationTaskMapperEx.updateAttachmentList(attachments, newEntity.getCustom5());
                                }
                                newEntity = null;
                                break;
                            }
                        }
                        //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                        //没被置null说明这条新数据是新增的，需要调用接口落盘
                        if (newEntity != null) {
                            synchronizationTaskMapperEx.insertDepotHeadSelective(newEntity);
                            List<DepotItem> depotItems = purchaseDepotMap.get(newEntity.getId());
                            synchronizationTaskMapperEx.insertDepotItemList(depotItems, tenantId);
                            List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                            if (attachments.size() > 0) {
                                synchronizationTaskMapperEx.insertAttachmentList(attachments, tenantId);
                            }
                        }

                    }
                }
                //报价单
                JSONArray quotationDepotHead = newJsonObject.getJSONArray("quotationDepotHead");
                if (null != quotationDepotHead && quotationDepotHead.size() > 0) {
                    List<DepotHead> oldQuotationDepotHead = synchronizationTaskMapperEx.selectECSDepotHeadByType("厂家报价");
                    List<DepotHead> newQuotationDepotHead = JSONObject.parseArray(newJsonObject.getJSONArray("quotationDepotHead").toJSONString(), DepotHead.class);
                    Map<String, List<DepotItem>> quotationDepotMap = JSONObject.parseObject(newJsonObject.getJSONObject("quotationDepotMap").toJSONString())
                            .entrySet().stream()
                            .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), DepotItem.class)));

                    for (DepotHead newEntity : newQuotationDepotHead) {
                        newEntity.setUploadFlag("1");
                        newEntity.setTenantId(newEntity.getCustom5());
                        for (DepotHead oldEntity : oldQuotationDepotHead) {
                            if (newEntity.getId().equals(oldEntity.getId())) {
                                synchronizationTaskMapperEx.updateDepotHeadByPrimaryKeySelective(newEntity);
                                List<DepotItem> depotItems = quotationDepotMap.get(newEntity.getId());
                                if (depotItems != null && depotItems.size() > 0) {
                                    synchronizationTaskMapperEx.updateDepotItemList(depotItems,newEntity.getCustom5());
                                }
                                List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                                if (attachments.size() > 0) {
                                    synchronizationTaskMapperEx.updateAttachmentList(attachments,newEntity.getCustom5());
                                }
                                //新旧数据比对并操作后，将新数据从List中“移除”
                                newEntity = null;
                                break;
                            }
                        }
                        //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                        //没被置null说明这条新数据是新增的，需要调用接口落盘
                        if (newEntity != null) {
                            synchronizationTaskMapperEx.insertDepotHeadSelective(newEntity);
                            List<DepotItem> depotItems = quotationDepotMap.get(newEntity.getId());
                            synchronizationTaskMapperEx.insertDepotItemList(depotItems,newEntity.getCustom5());
                            List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                            if (attachments.size() > 0) {
                                synchronizationTaskMapperEx.insertAttachmentList(attachments,newEntity.getCustom5());
                            }
                        }
                    }
                }
                JSONArray accountHeads = newJsonObject.getJSONArray("accountHeads");
                if (null != accountHeads && accountHeads.size() > 0) {
                    List<String> typeList=new ArrayList<>();
                    typeList.add("付款");
                    typeList.add("预付款单");
                    typeList.add("运输付款");
//                    typeList.add("直发付款");
//                    typeList.add("直发预付款");
//                    typeList.add("直发运输付款");
                    List<AccountHead> oldAccountHeads = synchronizationTaskMapperEx.selectOldAccountHead(tenantId, typeList);
                    List<AccountHead> newAccountHeads = JSONObject.parseArray(newJsonObject.getJSONArray("accountHeads").toJSONString(), AccountHead.class);
                    Map<String, List<AccountItem>> accountDepotMap = JSONObject.parseObject(newJsonObject.getJSONObject("accountDepotMap").toJSONString())
                            .entrySet().stream()
                            .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), AccountItem.class)));

                    for (AccountHead newEntity : newAccountHeads) {
                        if (!tenantId.equals(newEntity.getTenantId())) {
                            newEntity.setUploadFlag("1");
                            newEntity.setTenantId(tenantId);
                            for (AccountHead oldEntity : oldAccountHeads) {
                                if (newEntity.getId().equals(oldEntity.getId())) {
                                    //新旧数据比对并操作后，将新数据从List中“移除”
                                    synchronizationTaskMapperEx.updateAccountHeadSelective(newEntity);
                                    List<AccountItem> accountItems = accountDepotMap.get(newEntity.getId());
                                    synchronizationTaskMapperEx.updateAccountItemListSelective(accountItems, tenantId);
                                    List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                                    if (attachments.size() > 0) {
                                        synchronizationTaskMapperEx.updateAttachmentList(attachments, tenantId);
                                    }
                                    newEntity = null;
                                    break;
                                }
                            }
                            //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                            //没被置null说明这条新数据是新增的，需要调用接口落盘
                            if (newEntity != null) {
                                synchronizationTaskMapperEx.insertAccountHeadSelective(newEntity);
                                List<AccountItem> accountItems = accountDepotMap.get(newEntity.getId());
                                synchronizationTaskMapperEx.insertAccountItemListSelective(accountItems, tenantId);
                                List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                                if (attachments.size() > 0) {
                                    synchronizationTaskMapperEx.insertAttachmentList(attachments, tenantId);
                                }
                            }

                        }
                    }
                }

                //提前收款
                JSONArray outAccountHeads = newJsonObject.getJSONArray("outAccountHeads");
                if (null != outAccountHeads && outAccountHeads.size() > 0) {
                    List<String> typeList=new ArrayList<>();
                    typeList.add("预收款");
                    List<AccountHead> oldOutAccountHeads = synchronizationTaskMapperEx.selectOldAccountHead(tenantId, typeList);
                    List<AccountHead> newOutAccountHeads = JSONObject.parseArray(newJsonObject.getJSONArray("outAccountHeads").toJSONString(), AccountHead.class);
//                    Map<String, List<AccountItem>> accountDepotMap = JSONObject.parseObject(newJsonObject.getJSONObject("outAccountDepotMap").toJSONString())
//                            .entrySet().stream()
//                            .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), AccountItem.class)));

                    for (AccountHead newEntity : newOutAccountHeads) {
                        newEntity.setUploadFlag("1");
                        newEntity.setTenantId(tenantId);
                        for (AccountHead oldEntity : oldOutAccountHeads) {
                            if (newEntity.getId().equals(oldEntity.getId())) {
                                //新旧数据比对并操作后，将新数据从List中“移除”
                                synchronizationTaskMapperEx.updateAccountHeadSelective(newEntity);
//                                    List<AccountItem> accountItems = accountDepotMap.get(newEntity.getId());
//                                    synchronizationTaskMapperEx.updateAccountItemListSelective(accountItems, tenantId);
                                List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                                if (attachments.size() > 0) {
                                    synchronizationTaskMapperEx.updateAttachmentList(attachments, tenantId);
                                }
                                newEntity = null;
                                break;
                            }
                        }
                        //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                        //没被置null说明这条新数据是新增的，需要调用接口落盘
                        if (newEntity != null) {
                            synchronizationTaskMapperEx.insertAccountHeadSelective(newEntity);
//                                List<AccountItem> accountItems = accountDepotMap.get(newEntity.getId());
//                                synchronizationTaskMapperEx.insertAccountItemListSelective(accountItems, tenantId);
                            List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                            if (attachments.size() > 0) {
                                synchronizationTaskMapperEx.insertAttachmentList(attachments, tenantId);
                            }
                        }
                    }
                }
                //盘点单
                JSONArray checkDepotHead = newJsonObject.getJSONArray("checkDepotHead");
                if (null != checkDepotHead && checkDepotHead.size() > 0) {
                    List<DepotHead> oldCheckDepotHead = synchronizationTaskMapperEx.selectOldDepotHeadByType(tenantId, "盘点单");
                    List<DepotHead> newCheckDepotHead = JSONObject.parseArray(newJsonObject.getJSONArray("checkDepotHead").toJSONString(), DepotHead.class);
                    Map<String, List<DepotItem>> checkDepotMap = JSONObject.parseObject(newJsonObject.getJSONObject("checkDepotMap").toJSONString())
                            .entrySet().stream()
                            .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), DepotItem.class)));

                    for (DepotHead newEntity : newCheckDepotHead) {
                        newEntity.setUploadFlag("1");
                        newEntity.setTenantId(newEntity.getCustom5());
                        for (DepotHead oldEntity : oldCheckDepotHead) {
                            if (newEntity.getId().equals(oldEntity.getId())) {
                                synchronizationTaskMapperEx.updateDepotHeadByPrimaryKeySelective(newEntity);
                                List<DepotItem> depotItems = checkDepotMap.get(newEntity.getId());
                                if (depotItems != null && depotItems.size() > 0) {
                                    synchronizationTaskMapperEx.updateDepotItemList(depotItems,newEntity.getCustom5());
                                }
                                List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                                if (attachments.size() > 0) {
                                    synchronizationTaskMapperEx.updateAttachmentList(attachments,newEntity.getCustom5());
                                }
                                //新旧数据比对并操作后，将新数据从List中“移除”
                                newEntity = null;
                                break;
                            }
                        }
                        //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                        //没被置null说明这条新数据是新增的，需要调用接口落盘
                        if (newEntity != null) {
                            synchronizationTaskMapperEx.insertDepotHeadSelective(newEntity);
                            List<DepotItem> depotItems = checkDepotMap.get(newEntity.getId());
                            synchronizationTaskMapperEx.insertDepotItemList(depotItems,newEntity.getCustom5());
                            List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                            if (attachments.size() > 0) {
                                synchronizationTaskMapperEx.insertAttachmentList(attachments,newEntity.getCustom5());
                            }
                        }
                    }
                }
                //其它出入库
                JSONArray otherDepotHead = newJsonObject.getJSONArray("otherDepotHead");
                if (null != otherDepotHead && otherDepotHead.size() > 0) {
                    List<DepotHead> oldOtherDepotHead =  synchronizationTaskMapperEx.selectOldDepotHeadByType(tenantId, "其它");
                    List<DepotHead> newOtherDepotHead = JSONObject.parseArray(newJsonObject.getJSONArray("otherDepotHead").toJSONString(), DepotHead.class);
                    Map<String, List<DepotItem>> otherDepotMap = JSONObject.parseObject(newJsonObject.getJSONObject("otherDepotMap").toJSONString())
                            .entrySet().stream()
                            .collect(Collectors.toMap(Map.Entry::getKey, entry -> JSONObject.parseArray(String.valueOf(entry.getValue()), DepotItem.class)));

                    for (DepotHead newEntity : newOtherDepotHead) {
                        newEntity.setUploadFlag("1");
                        newEntity.setTenantId(tenantId);
                        for (DepotHead oldEntity : oldOtherDepotHead) {
                            if (newEntity.getId().equals(oldEntity.getId())) {
                                //新旧数据比对并操作后，将新数据从List中“移除”
                                synchronizationTaskMapperEx.updateDepotHeadByPrimaryKeySelective(newEntity);
                                List<DepotItem> depotItems = otherDepotMap.get(newEntity.getId());
                                if (depotItems != null && depotItems.size() > 0) {
                                    synchronizationTaskMapperEx.updateDepotItemList(depotItems, newEntity.getCustom5());
                                }
                                List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                                if (attachments.size() > 0) {
                                    synchronizationTaskMapperEx.updateAttachmentList(attachments, newEntity.getCustom5());
                                }
//                                //更新当前库存
//                                updateCurrentStockByNotTenantId(newEntity.getId());
                                //更新当前库存
                                if ("1".equals(newEntity.getStatus())){
                                    updateCurrentStockByHeaderIdNotTenantId(newEntity.getId(),true);
                                }
                                newEntity = null;
                                break;
                            }
                        }
                        //遍历完成之后，如果新数据在旧数据中有主键对应，则肯定会被置null
                        //没被置null说明这条新数据是新增的，需要调用接口落盘
                        if (newEntity != null) {
                            synchronizationTaskMapperEx.insertDepotHeadSelective(newEntity);
                            List<DepotItem> depotItems = otherDepotMap.get(newEntity.getId());
                            synchronizationTaskMapperEx.insertDepotItemList(depotItems, tenantId);
                            List<Attachment> attachments = attachmentMap.get(newEntity.getId());
                            if (attachments.size() > 0) {
                                synchronizationTaskMapperEx.insertAttachmentList(attachments, tenantId);
                            }
                            //更新当前库存
//                            updateCurrentStockByNotTenantId(newEntity.getId());
                            //更新当前库存
                            if ("1".equals(newEntity.getStatus())){
                                updateCurrentStockByHeaderIdNotTenantId(newEntity.getId(),true);
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            JshException.writeFail(logger, e, "zh");
        }
    }

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    public void updateCurrentStockByHeaderIdNotTenantId(String headerId,boolean updateFlag) throws Exception {
        List<DepotItem> detailList = synchronizationTaskMapperEx.getDepotItemListByHeaderId(headerId);
        DepotHead depotHead = depotHeadService.getDepotHeadById(headerId);
        if (null != detailList && detailList.size() > 0) {
            for (DepotItem depotItem : detailList) {
                int stockFlag=0; //0-无 1-增 2-减
                if ("出库".equals(depotHead.getType())){
                    if (updateFlag){
                        stockFlag=2;
                    }else {
                        stockFlag=1;
                    }
                }else if ("入库".equals(depotHead.getType())){
                    if (updateFlag){
                        stockFlag=1;
                    }else {
                        stockFlag=2;
                    }
                }
                updateCurrentStockNotTenantId(depotItem,stockFlag);
            }
        }
    }

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    public void updateCurrentStockNotTenantId(DepotItem depotItem,int stockFlag) {
        Depot depot=null;
        String depotId=null;
        BigDecimal operNumber=BigDecimal.ZERO;
        MaterialCurrentStock materialCurrentStock=null;
        try {
            depotId=depotItem.getDepotId();
            depot = depotService.getDepot(depotId);
            if (depot !=null){
                materialCurrentStock = getCurrentStockByIdList(depotItem.getMaterialId(), depotId, depot.getTenantId());
                switch (stockFlag){
                    case 1:
                        operNumber=depotItem.getOperNumber().abs();
                        break;
                    case 2:
                        operNumber= operNumber.subtract(depotItem.getOperNumber().abs());
                        break;
                }
                if (materialCurrentStock !=null ){
                    materialCurrentStock.setCurrentNumber(materialCurrentStock.getCurrentNumber().add(operNumber));
                    materialCurrentStock.setUploadFlag("0");
                    synchronizationTaskMapperEx.updateCurrentStockByPrimaryKeySelective(materialCurrentStock);
                }else {
                    materialCurrentStock = new MaterialCurrentStock();
                    materialCurrentStock.setMaterialId(depotItem.getMaterialId());
                    materialCurrentStock.setDepotId(depotId);
                    materialCurrentStock.setCurrentNumber(operNumber);
                    materialCurrentStock.setUploadFlag("0");
                    materialCurrentStock.setId(IdUtils.getUUID());
                    synchronizationTaskMapperEx.insertCurrentStockSelective(materialCurrentStock);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void  updateCurrentStockByNotTenantId(String headerId){
        List<DepotItem> detailList = synchronizationTaskMapperEx.getDepotItemListByHeaderId(headerId);
        if (null != detailList && detailList.size() > 0) {
            for (DepotItem depotItem : detailList) {
                String materialId = depotItem.getMaterialId();
                String depotId = depotItem.getDepotId();
                List<MaterialCurrentStock> list = synchronizationTaskMapperEx.getCurrentByTenantId(depotItem.getTenantId(),materialId,depotId);
                MaterialCurrentStock materialCurrentStock = new MaterialCurrentStock();
                materialCurrentStock.setMaterialId(materialId);
                materialCurrentStock.setDepotId(depotId);
                List<String> depotList = new ArrayList<>();
                if (StringUtils.isNotEmpty(depotId)) {
                    depotList.add(depotId);
                }
                BigDecimal stock=BigDecimal.ZERO;
                List<MaterialInitialStock> materialInitialStockList = synchronizationTaskMapperEx.getMaterialInitialStock(depotItem.getTenantId(),materialId,depotId);

                if(materialInitialStockList!=null && materialInitialStockList.size()>0) {
                    stock = materialInitialStockList.get(0).getNumber();
                }
                //盘点复盘后数量的变动
                BigDecimal stockCheckSum = synchronizationTaskMapperEx.getStockCheckSumByDepotListAndTenantId(depotList, materialId,depotItem.getTenantId());
                DepotItemVo4Stock stockObj = synchronizationTaskMapperEx.getStockByParamWithDepotListAndTenantId(depotList, materialId,depotItem.getTenantId());
                BigDecimal stockSum = BigDecimal.ZERO;
                if (stockObj != null) {
                    BigDecimal inTotal = stockObj.getInTotal();
                    BigDecimal transfInTotal = stockObj.getTransfInTotal();
                    BigDecimal assemInTotal = stockObj.getAssemInTotal();
                    BigDecimal disAssemInTotal = stockObj.getDisAssemInTotal();
                    BigDecimal outTotal = stockObj.getOutTotal();
                    BigDecimal transfOutTotal = stockObj.getTransfOutTotal();
                    BigDecimal assemOutTotal = stockObj.getAssemOutTotal();
                    BigDecimal disAssemOutTotal = stockObj.getDisAssemOutTotal();
                    stockSum = inTotal.add(transfInTotal).add(assemInTotal).add(disAssemInTotal)
                            .subtract(outTotal).subtract(transfOutTotal).subtract(assemOutTotal).subtract(disAssemOutTotal);
                }
                BigDecimal currentNumber=stock.add(stockCheckSum).add(stockSum);

                materialCurrentStock.setCurrentNumber(currentNumber);
                materialCurrentStock.setUploadFlag("0");
                if (list != null && list.size() > 0) {
                    String mcsId = list.get(0).getId();
                    materialCurrentStock.setId(mcsId);
                    synchronizationTaskMapperEx.updateCurrentStockByPrimaryKeySelective(materialCurrentStock);
                } else {
                    materialCurrentStock.setId(IdUtils.getUUID());
                    materialCurrentStock.setTenantId(tenantId);
                    synchronizationTaskMapperEx.insertCurrentStockSelective(materialCurrentStock);
                }
            }
        }

    }


    public SystemConfig getSystemConfig(String id) throws Exception {
        SystemConfig result = null;
        try {
            result = systemConfigMapper.selectByPrimaryKey(id);
        } catch (Exception e) {
            JshException.readFail(logger, e, this.getLanCode());
        }
        return result;
    }

    public List<SystemConfig> getSystemConfig() throws Exception {
        SystemConfigExample example = new SystemConfigExample();
        example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
        List<SystemConfig> list = null;
        try {
            list = systemConfigMapper.selectByExample(example);
        } catch (Exception e) {
            JshException.readFail(logger, e, this.getLanCode());
        }
        return list;
    }

    public List<SystemConfig> select(String companyName, int offset, int rows) throws Exception {
        List<SystemConfig> list = null;
        try {
            list = systemConfigMapperEx.selectByConditionSystemConfig(companyName, offset, rows);
        } catch (Exception e) {
            JshException.readFail(logger, e, this.getLanCode());
        }
        return list;
    }

    public Long countSystemConfig(String companyName) throws Exception {
        Long result = null;
        try {
            result = systemConfigMapperEx.countsBySystemConfig(companyName);
        } catch (Exception e) {
            JshException.readFail(logger, e, this.getLanCode());
        }
        return result;
    }

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    public int insertSystemConfig(JSONObject obj, HttpServletRequest request) throws Exception {
        SystemConfig systemConfig = JSONObject.parseObject(obj.toJSONString(), SystemConfig.class);
        systemConfig.setUploadFlag("0");
        int result = 0;
        try {
            if (userService.checkIsTestUser()) {
                result = -1;
            } else {
                result = systemConfigMapper.insertSelective(systemConfig);
                logService.insertLog("系统配置",
                        new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(systemConfig.getCompanyName()).toString(), request);
            }
        } catch (Exception e) {
            JshException.writeFail(logger, e, this.getLanCode());
        }
        return result;
    }

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    public int updateSystemConfig(JSONObject obj, HttpServletRequest request) throws Exception {
        SystemConfig systemConfig = JSONObject.parseObject(obj.toJSONString(), SystemConfig.class);
        systemConfig.setUploadFlag("0");
        int result = 0;
        try {
            if (userService.checkIsTestUser()) {
                result = -1;
            } else {
                result = systemConfigMapper.updateByPrimaryKeySelective(systemConfig);
                logService.insertLog("系统配置",
                        new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(systemConfig.getCompanyName()).toString(), request);
            }
        } catch (Exception e) {
            JshException.writeFail(logger, e, this.getLanCode());
        }
        return result;
    }

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    public int deleteSystemConfig(String id, HttpServletRequest request) throws Exception {
        return batchDeleteSystemConfigByIds(id.toString());
    }

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    public int batchDeleteSystemConfig(String ids, HttpServletRequest request) throws Exception {
        return batchDeleteSystemConfigByIds(ids);
    }

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    public int batchDeleteSystemConfigByIds(String ids) throws Exception {
        logService.insertLog("系统配置",
                new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_DELETE).append(ids).toString(),
                StringUtil.getRequest());
        User userInfo = userService.getCurrentUser();
        String[] idArray = ids.split(",");
        int result = 0;
        try {
            if (userService.checkIsTestUser()) {
                result = -1;
            } else {
                result = systemConfigMapperEx.batchDeleteSystemConfigByIds(new Date(), userInfo == null ? null : userInfo.getId(), idArray);
            }
        } catch (Exception e) {
            JshException.writeFail(logger, e, this.getLanCode());
        }
        return result;
    }

    public int checkIsNameExist(String id, String name) throws Exception {
        SystemConfigExample example = new SystemConfigExample();
        example.createCriteria().andIdNotEqualTo(id).andCompanyNameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
        List<SystemConfig> list = null;
        try {
            list = systemConfigMapper.selectByExample(example);
        } catch (Exception e) {
            JshException.readFail(logger, e, this.getLanCode());
        }
        return list == null ? 0 : list.size();
    }

    /**
     * 获取仓库开关
     *
     * @return
     * @throws Exception
     */
    public boolean getDepotFlag() throws Exception {
        boolean depotFlag = false;
        List<SystemConfig> list = getSystemConfig();
        if (list.size() > 0) {
            String flag = list.get(0).getDepotFlag();
            if (("1").equals(flag)) {
                depotFlag = true;
            }
        }
        return depotFlag;
    }

    /**
     * 获取客户开关
     *
     * @return
     * @throws Exception
     */
    public boolean getCustomerFlag() throws Exception {
        boolean customerFlag = false;
        List<SystemConfig> list = getSystemConfig();
        if (list.size() > 0) {
            String flag = list.get(0).getCustomerFlag();
            if (("1").equals(flag)) {
                customerFlag = true;
            }
        }
        return customerFlag;
    }

    /**
     * 获取负库存开关
     *
     * @return
     * @throws Exception
     */
    public boolean getMinusStockFlag() throws Exception {
        boolean minusStockFlag = false;
        List<SystemConfig> list = getSystemConfig();
        if (list.size() > 0) {
            String flag = list.get(0).getMinusStockFlag();
            if (("1").equals(flag)) {
                minusStockFlag = true;
            }
        }
        return minusStockFlag;
    }

    public String getLanCode() {
        HttpServletRequest request = StringUtil.getRequest();
        return redisService.getLanCodeFromSession(request);
    }

    public static void main(String[] args) {
        DepotHead h = new DepotHead();
        h.setId("12321321321321");
        DepotHead head = new DepotHead();
        head.setId("12321321321321");
        if (Objects.equals(h, head)) {
            System.out.println(true);
        }
    }

    public List<String> getTenantDepotIdList() {
        return synchronizationTaskMapperEx.getTenantDepotIdList(tenantId);
    }

    public JSONObject getBasicData(String newTenantId,boolean flag) {
        JSONObject oldJsonObject = new JSONObject();
        Map<String, List<Attachment>> attachmentMap = new HashMap<>();
        Map<String, List<MaterialExtend>> materialExtendMap = new HashMap<>();
        Map<String, Unit> unitMap = new HashMap<>();
        //商品
        List<Material> materials = new ArrayList<>();
        if (flag){
            materials = synchronizationTaskMapperEx.selectMaterialByTime(newTenantId);
            if (materials != null && materials.size() > 0) {
                for (Material material : materials) {
                    //单位
                    Unit unit = unitMapper.selectByPrimaryKey(material.getUnitId());
                    unitMap.put(material.getId(), unit);
                    //图片
//                AttachmentExample example = new AttachmentExample();
//                example.createCriteria().andHeaderIdEqualTo(material.getId()).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
//                List<Attachment> attachments = attachmentMapper.selectByExample(example);
//                attachmentMap.put(material.getId(), attachments);
                    //商品价格
                    MaterialExtendExample materialExtendExample = new MaterialExtendExample();
                    materialExtendExample.createCriteria().andMaterialIdEqualTo(material.getId()).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
                    List<MaterialExtend> materialExtends = materialExtendMapper.selectByExample(materialExtendExample);
                    materialExtendMap.put(material.getId(), materialExtends);
                }
            }
        }
        oldJsonObject.put("materials", materials);
        oldJsonObject.put("materialExtendMap", materialExtendMap);
        oldJsonObject.put("attachmentMap", attachmentMap);
        oldJsonObject.put("unitMap", unitMap);
        //商品类型
        MaterialCategoryExample materialCategoryExample = new MaterialCategoryExample();
        materialCategoryExample.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
        List<MaterialCategory> materialCategories = materialCategoryMapper.selectByExample(materialCategoryExample);
        oldJsonObject.put("materialCategories", materialCategories);

//        List<AccountHead> accountHeads = synchronizationTaskMapperEx.selectCustom5AccountHead(newTenantId);
//        oldJsonObject.put("accountHeads", accountHeads);
//        Map<String, List<AccountItem>> accountItemMap = new HashMap<>();
//        if (accountHeads != null && accountHeads.size()>0){
//            for (AccountHead accountHead : accountHeads){
//                List<AccountItem> accountItems = synchronizationTaskMapperEx.selectAccountItem(accountHead.getId());
//                accountItemMap.put(accountHead.getId(),accountItems);
//            }
//        }
////        财务单据表体
////        List<AccountItem> accountItems = synchronizationTaskMapperEx.selectAccountItem(tenantId);
//        oldJsonObject.put("accountItems", accountItemMap);
//        //商品类型
//        List<MaterialCategory> materialCategoryList = synchronizationTaskMapperEx.selectMaterialCategoryByTime();
//        //商品类型
//        List<MaterialExtend> materialExtendList = synchronizationTaskMapperEx.selectMaterialExtendByTime();
//        //多单位
//        List<Unit> unitList = synchronizationTaskMapperEx.selectUnitByTime();
//        //租户
//        List<Tenant> tenantList = synchronizationTaskMapperEx.selectTenantTime();
        //账户信息
        List<Account> accounts = synchronizationTaskMapperEx.selectAccountList();
        oldJsonObject.put("accounts", accounts);
        //用户
        List<User> userList = synchronizationTaskMapperEx.selectUserTime();
        oldJsonObject.put("userList", userList);
        //供应商
        List<Supplier> suppliers = synchronizationTaskMapperEx.selectNewSupplier("供应商", newTenantId);
        oldJsonObject.put("suppliers", suppliers);
//        //用户类型
//        List<UserCategory> userCategoryList = synchronizationTaskMapperEx.selectUserCategoryTime();
//        //用户/角色/模块关系
//        List<UserBusiness> userBusinessList = synchronizationTaskMapperEx.selectUserBusinessTime();
//        //角色表
//        List<Role> roleList = synchronizationTaskMapperEx.selectRoleTime();
//        //经手人表
//        List<Person> personList = synchronizationTaskMapperEx.selectPersonTime();
//        //机构表
//        List<Organization> organizationList = synchronizationTaskMapperEx.selectOrganizationTime();
//        //机构用户关系表
//        List<OrgaUserRel> orgaUserRelList = synchronizationTaskMapperEx.selectOrgaUserRelTime();
//        //机构用户关系表
        //促销
        Map<String, List<PromotionItem>> promotionItemMap = new HashMap<>();
        Map<String, List<PromotionGift>> promotionGiftMap = new HashMap<>();
        Map<String, List<PromotionSupplier>> promotionSupplierMap = new HashMap<>();
        List<PromotionHead> promotionHeadList = synchronizationTaskMapperEx.selectPromotionHeadTime(newTenantId);
        oldJsonObject.put("promotionHeadList", promotionHeadList);
        if (promotionHeadList != null && promotionHeadList.size() > 0) {
            for (PromotionHead promotionHead : promotionHeadList) {
                List<PromotionItem> promotionItemList = synchronizationTaskMapperEx.selectPromotionItemTime(promotionHead.getId());
                promotionItemMap.put(promotionHead.getId(), promotionItemList);
                if (promotionHead.getPromotionType() == 3) {
                    for (PromotionItem promotionItem : promotionItemList) {
                        List<PromotionGift> promotionGiftList = synchronizationTaskMapperEx.selectPromotionGiftTime(promotionItem.getId());
                        promotionGiftMap.put(promotionItem.getId(), promotionGiftList);
                    }
                }
                List<PromotionSupplier> promotionSupplierList = synchronizationTaskMapperEx.selectPromotionSupplierTime(promotionHead.getId());
                promotionSupplierMap.put(promotionHead.getId(), promotionSupplierList);
//                List<PromotionDepot> promotionDepotList = synchronizationTaskMapperEx.selectPromotionDepotTime();
//                oldJsonObject.put("promotionDepotList", promotionDepotList);
            }
        }
        oldJsonObject.put("promotionItemMap", promotionItemMap);
        oldJsonObject.put("promotionGiftMap", promotionGiftMap);
        oldJsonObject.put("promotionSupplierMap", promotionSupplierMap);

        List<Depot> depotList = synchronizationTaskMapperEx.selectDepotTime();
        oldJsonObject.put("depotList", depotList);
        List<AuditSynchronization> auditSynchronizationList = synchronizationTaskMapperEx.selectAuditSynchronization(newTenantId);
        oldJsonObject.put("auditSynchronizationList", auditSynchronizationList);

        //返利表头
        List<Rebate> rebates = synchronizationTaskMapperEx.selectRebate(newTenantId);
        Map<String, List<RebateItem>> rebateItemMap = new HashMap<>();
        oldJsonObject.put("rebates", rebates);
        if (rebates != null && rebates.size() > 0) {
            for (Rebate rebate : rebates) {
                //返利表体
                List<RebateItem> rebateItems = synchronizationTaskMapperEx.selectRebateItem(rebate.getId());
                rebateItemMap.put(rebate.getId(), rebateItems);
//                //返利商品
//                List<RebateMaterial> rebateMaterials = synchronizationTaskMapperEx.selectRebateMaterial(tenantId);
//                oldJsonObject.put("rebateMaterials", rebateMaterials);
//                //返利规则
//                List<RebateRule> rebateRules = synchronizationTaskMapperEx.selectRebateRule(tenantId);
//                oldJsonObject.put("rebateRules", rebateRules);
            }
        }
        oldJsonObject.put("rebateItemMap", rebateItemMap);

        List<UserCategory> userCategories = synchronizationTaskMapperEx.selectUserCategoryTime();
        oldJsonObject.put("userCategories", userCategories);
//        oldJsonObject.put("materialList", materialList);
//        oldJsonObject.put("materialCategoryList", materialCategoryList);
//        oldJsonObject.put("materialExtendList", materialExtendList);
//        oldJsonObject.put("unitList", unitList);
//        oldJsonObject.put("tenantList", tenantList);
//        oldJsonObject.put("userCategoryList", userCategoryList);
//        oldJsonObject.put("userBusinessList", userBusinessList);
//        oldJsonObject.put("roleList", roleList);
//        oldJsonObject.put("personList", personList);
//        oldJsonObject.put("organizationList", organizationList);
//        oldJsonObject.put("orgaUserRelList", orgaUserRelList);
        return oldJsonObject;
    }

    public SystemConfig getSystemConfigByTenantId() throws Exception {
        SystemConfigExample example = new SystemConfigExample();
        example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
        List<SystemConfig> list = null;
        try {
            list = systemConfigMapper.selectByExample(example);
        } catch (Exception e) {
            JshException.readFail(logger, e, this.getLanCode());
        }
        if (null != list && list.size()>0){
            return list.get(0);
        }
        return null;
    }

    public MaterialCurrentStock getCurrentStockByIdList(String materialId,String depotId ,String tenantId) throws Exception {
        MaterialCurrentStock materialCurrentStock = null;
        try {
            materialCurrentStock = synchronizationTaskMapperEx.getCurrentStockByIdList(materialId,depotId,tenantId);
        } catch (Exception e) {
            JshException.readFail(logger, e, this.getLanCode());
        }
        return materialCurrentStock;
    }
}
